Created
November 10, 2023 06:42
-
-
Save error9900/5c15002c0052a0e3c998499bfd2dfd5c to your computer and use it in GitHub Desktop.
Get completed items from Todoist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Put your token in data/token.txt. | |
Completed items are written to `output/completed_items.py` as a Python dictionary. | |
Reference: https://developer.todoist.com/sync/v9/#get-all-completed-items | |
""" | |
import requests | |
def load_token(): | |
with open("data/token.txt", "r", encoding="utf-8") as f: | |
line = f.readline() | |
token = line.strip() | |
return token | |
def get_completed_items(): | |
parameters = {"limit": 200} | |
response = requests.post( | |
"https://api.todoist.com/sync/v9/completed/get_all", | |
headers={"Authorization": f"Bearer {load_token()}"}, | |
json=parameters, | |
timeout=60, | |
) | |
response.raise_for_status() | |
return response.json() | |
def write_completed_items_to_file(completed_items): | |
file_path = "output/completed_items.py" | |
with open(file_path, "w", encoding="utf-8") as f: | |
f.write(f"completed_items = {str(completed_items)}") | |
def main(): | |
write_completed_items_to_file(get_completed_items()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment