Last active
January 18, 2024 08:17
-
-
Save fpapado/9e1e6bd133664376eaa5f6855712f28b to your computer and use it in GitHub Desktop.
Gets and prints the tasks for "today", from the Todoist API. Intended to be used alongside https://github.com/Doist/todoist-python.
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
# Use the todoist API to get tasks from the current day | |
import todoist | |
from datetime import datetime | |
# Log user in; switch to OAuth eventually... | |
api = todoist.TodoistAPI() | |
def get_todays_tasks(email, password): | |
""" | |
Get tasks due on the current utc day | |
:return: list of task dicts | |
""" | |
# user = api.user.login(email, password) | |
api.user.login(email, password) | |
tasks_today = [] | |
# Sync (load) data | |
response = api.sync() | |
# Get "today", only keep Day XX Mon, which Todoist uses | |
today = datetime.utcnow().strftime("%a %d %b") | |
for item in response['items']: | |
due = item['due_date_utc'] | |
if due: | |
# Slicing :10 gives us the relevant parts | |
if due[:10] == today: | |
tasks_today.append(item) | |
return tasks_today |
They changed the API at some point. This is what works as of today:
today = datetime.utcnow().strftime("%Y-%m-%d")
api = TodoistAPI(<FILL>)
api.sync()
for item in api.state['items']:
if item['due'] is not None and item['due']['date'] == today:
...
Is it possible to grab All tasks, sub-tasks & comments (which are images\screenshots)?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OH! It worked!
Thank you so much!
For some reason, the Todoist API did not work when I tried to use a token, but logging in by email worked.
Thanks so much for this!