-
Notifications
You must be signed in to change notification settings - Fork 0
/
notion.py
79 lines (57 loc) · 1.92 KB
/
notion.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
import os
from notion_client import Client
import json
import datetime
# import sync
from dotenv import load_dotenv
load_dotenv()
database = os.getenv("NOTION_DATABASE")
token = os.getenv("NOTION_TOKEN")
notion = Client(auth=token)
TOMORROW = True
def get_message():
return "Here is the rehearsal call for today!\n\n" + '<font="Courier">' + get_call() + '</font>'
def get_call():
#get iso 8601 date for tomorrow
tomorrow = datetime.date.today()
if TOMORROW:
tomorrow += datetime.timedelta(days=1)
response = notion.databases.query(
database_id=database,
filter={
"property": "Date",
"date": {
"equals": tomorrow.isoformat()
}
}
)
if len(response["results"]) == 0:
raise Exception("no call")
# print (response[0]["properties"]["Name"]["title"][0]["plain_text"])
for i in response["results"]:
info = "Rehearsal: "
name = i['properties']['Name']["title"]
if len(name) != 0:
name = name[0]["plain_text"]
info += name
info += '\nDate: '
date = i['properties']['Date']['date']['start']
date = datetime.datetime.strptime(date, '%Y-%m-%d').strftime('%m/%d/%Y')
info += date + '\nCalled: '
called = i['properties']['Called']['rich_text']
if len(called) != 0:
called = called[0]['plain_text']
info += called
info += '\nTime: '
time = i['properties']['Time']['rich_text']
if len(time) != 0:
time = time[0]['plain_text']
info += time
info += '\nNotes: '
notes = i['properties']['Notes']['rich_text']
if len(notes) != 0:
notes = notes[0]['plain_text']
info += notes
info += '\n'
return info, tomorrow.strftime("%m/%d")
print(get_call()[0])