Skip to content

Instantly share code, notes, and snippets.

@tokida
Created January 6, 2017 15:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tokida/40478d337fe8d11443bf2d2dbd22365b to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import requests
from datetime import datetime as dt
def getAllList(token):
q = {
'token': token,
'seq_no': 0,
'seq_no_global': 0,
'resource_types': '["items"]'
}
r = requests.get('https://todoist.com/API/v7/sync', params=q)
r.encoding = r.apparent_encoding
return r.json()["items"]
def getList(token, project_id):
res = getAllList(token)
todos = []
for item in res:
if item['project_id'] is not None and item['project_id'] == project_id:
# print item['project_id']
if item['due_date_utc'] is not None:
if item['date_string'] is not "" or item['date_string'] is not None:
todo = []
tstr = item['due_date_utc'].replace('+0000', 'UTC')
tdatetime = dt.strptime(tstr, '%a %d %b %Y %H:%M:%S %Z')
todo.append(tdatetime)
todo.append(item['date_string'].encode('utf-8'))
todo.append(item['content'].encode('utf-8'))
todos.append(todo)
# print todo
return todos
if __name__ == "__main__":
token = '<TOKEN>'
project_id = <PROJECT_ID>
todos = getList(token, project_id)
todos.sort(key=lambda x: x[0])
for todo in todos:
print '%s, %s' % (
todo[1],
todo[2]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment