Wednesday, May 20, 2015

Python example to Add task in Todoist

A simple script that will prompt you for a task description and date, then add it to the project in Todoist.


Requires:
* https://github.com/Doist/todoist-python  - View the Readme for installing the todoist-python library
* Python 2.7+
* PIP: https://pypi.python.org/pypi/pip


Code:

import todoist

api = todoist.TodoistAPI('HERE_IS_MY_API_KEY')
task_desc = input('Enter the task: ')
task_time = input('When (optional): ')  
item = api.items.add(task_desc, MY_PROJECT_ID, date_string=task_time)
api.commit()



I just created a simple shortcut in my taskbar and it easily adds tasks to the project ID. I used the Inbox project Id from my account so everything goes in there. I can sort it later.

The "When" parameter recognizes the Todoist date/times such as:
  • today
  • tomorrow
  • 2 weeks
  • 1 month
If you press Enter, instead of adding a date, then the task is still added, but with no date.