-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (60 loc) · 2.52 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
import requests
from datetime import datetime
import json
with open('/home/zemmsoares/.config/polybar/custom-modules/notion/config.json', 'r') as f:
config = json.load(f)
NOTION_API_KEY = config['NOTION_API_KEY']
NOTION_DATABASE_ID = config['NOTION_DATABASE_ID']
# Define the API endpoint URL
url = 'https://api.notion.com/v1/databases/' + NOTION_DATABASE_ID + '/query'
# Define the request headers
headers = {
'Authorization': 'Bearer ' + NOTION_API_KEY,
'Content-Type': 'application/json',
'Notion-Version': '2021-08-16'
}
data = {}
# Send the POST request
response = requests.post(url, headers=headers, data=json.dumps(data))
# Check the response status code
if response.status_code == 200:
# Initialize the dictionaries and lists
tasks_by_date = {}
tasks_no_due_date = []
tasks_overdue = []
# Loop through the results
for result in response.json()['results']:
try:
status = result['properties']['Status']['status']['id']
except KeyError:
status = None
try:
due_date = result['properties']['Due']['date']['start']
except (KeyError, TypeError):
due_date = None
print(due_date)
print(status)
# Add the task to the appropriate group
if due_date == datetime.today().strftime('%Y-%m-%d') and status != 'done':
if due_date not in tasks_by_date:
tasks_by_date[due_date] = [result]
else:
tasks_by_date[due_date].append(result)
elif status != 'done' and due_date is not None and due_date <= datetime.today().strftime('%Y-%m-%d'):
tasks_overdue.append(result)
elif status != 'done' and due_date is None:
tasks_no_due_date.append(result)
#also adding future tasks into tasks_no_due_date
elif status != 'done' and due_date >= datetime.today().strftime('%Y-%m-%d'):
tasks_no_due_date.append(result);
# Print the results
today_count = len(tasks_by_date.get(datetime.today().strftime('%Y-%m-%d'), []))
#print(f'Tasks Due Today ({datetime.today().strftime("%Y-%m-%d")}): {today_count}')
no_due_date_count = len(tasks_no_due_date)
#print('\nTasks with No Due Date:', no_due_date_count)
overdue_count = len(tasks_overdue)
#print('\nTasks Overdue:', overdue_count)
print('%{{BEC407A}} {} %{{B#00B19F}} {} %{{B#444444}} {} '.format(overdue_count, today_count, no_due_date_count))
else:
print('Error:', response.status_code)
print(response.text)