Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import os
import webbrowser
from datetime import datetime
from dotenv import load_dotenv
from todoist.api import TodoistAPI
api_key = os.environ['TODOIST_KEY']
print('"TODOIST_KEY" not found in your environment variables')
api = TodoistAPI(api_key)
def get_all_tasks():
return api.state['items']
def get_all_projects():
return api.state['projects']
def pick_project(todoist_projects):
projects = []
print('todoist projects')
for n, project in enumerate(todoist_projects):
project_name = project['name'].encode(
'ascii', 'ignore').decode('ascii') # remove emojis
project_id = project['id']
print(f'{n + 1}: {project_name}')
project = int(input('which project id? '))
return projects[project - 1]
def find_tasks(todoist_tasks, todoist_project):
tasks = []
for task in todoist_tasks:
if['project_id'] == todoist_project:
content =['content']
when =['due']['date'] if['due'] else ''
creation_date =['date_added']
# if markdown link task then separate out
if content[0] == '[' and content[-1] == ')':
title = content.split('](')[0][1:].strip()
notes = content.split('](')[1][:-1].strip()
title = content
notes = ''
tasks.append({'title': title, 'notes': notes,
'when': when, 'creation_date': creation_date})
return tasks
def make_project():
things_project = f'IMPORT {"%m-%y %X")}'
purl = f'things:///add-project?title={things_project}&reveal=true'
return things_project
def add_to_things(things_tasks):
# create a new project/list to hold the imported tasks
list_title = make_project()
# tags must already exist, comma separated
tags = 'todoist'
for task in things_tasks:
title = task['title']
notes = task['notes']
when = task['when']
creation_date = task['creation_date']
print(f'...moving {title[:30]}...')
turl = f'things:///add?title={title}&notes={notes}&when={when}&tags={tags}&list={list_title}&creation-date={creation_date}'
print(f'tasks moved to things. find them in project {list_title}')
if __name__ == '__main__':
todoist_tasks = get_all_tasks()
todoist_projects = get_all_projects()
todoist_project = pick_project(todoist_projects)
things_tasks = find_tasks(todoist_tasks, todoist_project)
print(f'found {len(things_tasks)} matching tasks...')
cont = input('continue? (y/n) ')
if cont.lower() != 'y':
print('no tasks were moved.')
print('starting to move your tasks...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment