-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
91 lines (82 loc) · 3.46 KB
/
main.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
83
84
85
86
87
88
89
90
91
import os
import sys
from notion_client import Client
import things
import webbrowser
import pandas as pd
import datetime
import json
def main():
if not os.path.isfile('config.json'): # check to see if config exists
print("Error: Run config.py, no config found.")
sys.exit(0)
with open("config.json", "r") as jsonfile: # read config
data = json.load(jsonfile)
# user defaults
token = data['token']
database = data['database']
notion = Client(auth=token)
if not os.path.isfile('data.csv'): # check to see if data path exists
df = pd.DataFrame(columns=['id', 'name', 'date', 'tag'])
df.to_csv('data.csv', index=False)
df = pd.read_csv('data.csv')
x = len(df)
today = datetime.datetime.today().date()
database = notion.databases.query(
**{
"database_id": database,
}
)
projects = [x['title'] for x in things.projects()]
for entry in database['results']:
properties = entry['properties']
id = str(entry['id'])
completed = [x['notes'] for x in things.completed()]
if id not in df['id'].values: # if new entry
try:
date = properties['Date']['date']['start']
date = date.split('T')[0]
date = datetime.datetime.strptime(date, '%Y-%m-%d').date()
progress = properties['Progress']['select']['name']
name = properties['Name']['title'][0]['plain_text']
tag = properties['Tags']['multi_select'][0]['name']
if tag not in projects:
webbrowser.open('things:///add-project?title='+tag+'&area=Work')
projects = [x['title'] for x in things.projects()]
except:
date = None
progress = None
if (progress == "Not Started") and not (date < today): # things needs todos today or later
df.loc[x] = [id, name, date, tag]
webbrowser.open('things:///add?title='+name+'¬es='+id+'&when='+date.strftime('%Y-%m-%d')+'&list='+tag) # add to things
x += 1
elif (progress == "Completed") and not (date < today) and id not in completed: # got marked as completed but not in things
df.loc[x] = [id, name, date, tag]
notion.pages.update(id, properties={
'Progress': {'id': 'y%40%5DD',
'type': 'select',
'select': {'id': '33e9a473-dfc9-4531-8359-5d9bd10e2745',
'name': 'Not Started',
'color': 'red'}
}
})
x += 1
else: # otherwise check to see if completed
in_todo = False
for todo in things.todos():
if todo['notes'] == id:
in_todo = True
if not in_todo: # if things marked as completed, delete and update notion
notion.pages.update(id, properties={
'Progress': {'id': 'y%40%5DD',
'type': 'select',
'select': {'id': '5bde3130-3aa9-4d8b-993d-6a15051f3e2a',
'name': 'Completed',
'color': 'green'},
}
})
df = df[~df['id'].isin([id])]
df = df.reset_index(drop=True)
df.to_csv('data.csv', index=False)
if __name__ == "__main__":
main()