-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodoistinterface.py
executable file
·82 lines (66 loc) · 2.05 KB
/
todoistinterface.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import json
import ConfigParser
import os.path
import todoist
class ToDoistInterface(object):
"""Ugly wrapper for the ToDoist.com API"""
def __init__(self, token):
self.token = token
self.api = todoist.TodoistAPI(token)
self.api.sync()
def get_projects(self):
'''
Get all projects.
'''
return self.api.projects.all()
def get_uncompleted_todos(self, project_id):
'''
Get all uncompleted todo items.
'''
return [ i for i in self.api.items.all() if not i["checked"] ]
def get_completed_todos(self, project_id):
'''
Get all completed todo items.
'''
return [ i for i in self.api.items.all() if i["checked"] ]
def get_all_todos(self, project_id):
'''
Get all todo objects.
'''
return self.get_uncompleted_todos(project_id) + self.get_completed_todos(project_id)
def set_complete(self, item_id):
'''
Set a todo's state to complete.
item_id: the todoist ID of the todo.
'''
self.api.items.complete([item_id])
self.api.commit()
return True
def create_todo(self, name, project_id):
'''
Create a new todo.
name: the label for the todo item.
project_id: the id of the project in which to create a todo.
'''
add_res = self.api.items.add(name.encode('utf-8'), project_id)
self.api.commit()
return add_res
def get_inbox_id(self):
'''
Get the project ID for the Inbox project.
'''
return [ i for i in self.get_projects() if i["name"] == "Inbox" ][0]
def main():
config = ConfigParser.ConfigParser()
config.read(os.path.expanduser("~/.tothingist"))
api_key = config.get('login', 'api_token')
a = ToDoistInterface(api_key)
inbox_id = a.get_inbox_id()
import pprint
pprint.pprint(a.get_all_todos(inbox_id["id"]))
if __name__ == "__main__":
main()