-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_api.py
33 lines (26 loc) · 945 Bytes
/
test_api.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
import todoist
import os
import yaml
import string
appdir = os.path.dirname(os.path.realpath(__file__)) # rp, realpath
datadir = os.path.join(appdir, "data")
# Read config
with open(os.path.join(appdir, 'config.yaml'), 'r') as f:
config = yaml.load(f.read())
api = todoist.TodoistAPI(config['todoist_token'])
api.sync()
def get_archival_text(api):
projects = {}
for project in api.state['projects']:
projects[project['id']] = project['name']
tasks = []
for item in api.state['items']:
text = f"({string.ascii_uppercase[4 - item['priority']]}) {item['content']} +{projects[item['project_id']]}"
if item['due'] != None:
text += f" due:{item['due']['date']}"
tasks.append(text)
archival_text = ''
for task in sorted(tasks):
archival_text += task + "\n"
return archival_text
# print(f"({string.ascii_uppercase[4 - item['priority']]}) {item['content']}")