Skip to content

Instantly share code, notes, and snippets.

@fpapado
Last active January 18, 2024 08:17
Show Gist options
  • Save fpapado/9e1e6bd133664376eaa5f6855712f28b to your computer and use it in GitHub Desktop.
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.
# 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
@ochen1
Copy link

ochen1 commented Sep 22, 2020

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!

@ijoseph
Copy link

ijoseph commented Jan 24, 2021

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:
        ... 

@rolltidehero
Copy link

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