-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskManagerNotion.py
More file actions
58 lines (44 loc) · 2.17 KB
/
taskManagerNotion.py
File metadata and controls
58 lines (44 loc) · 2.17 KB
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
from notion.client import NotionClient
from notion.collection import NotionDate
from time import strftime
from datetime import datetime, date,timedelta
from twilio.rest import Client
# Obtain the `token_v2` value by inspecting your browser cookies on a logged-in (non-guest) session on Notion.so
client = NotionClient(token_v2="[YOUR TOKEN V2 (FROM COOKIES)]")
# Your Account Sid and Auth Token from twilio account
account_sid = "[TWILIO ACCOUT SID]"
auth_token = "[TWILIO AUTH TOKEN]"
myPhoneNumber = "[YOUR PHONE NUMBER (+33x xx xx xx xx for France)]"
twilioPhoneNumber = "[TWILIO PHONE NUMBER]"
twilioClient = Client(account_sid, auth_token)
# Access a database using the URL of the database page or the inline block
cvListeTotale = client.get_collection_view("[LINK TO MAIN DATABASE WITH ALL TASK TO DO]")
cvListeUrgente = client.get_collection_view("[LINK TO URGENT DATABASE]")
cvListeFinies = client.get_collection_view("[LINK TO THE DATABASE WITH ALL DONE TASK]")
def switchRowFromDatabase(toDatabase,row):
rowToAdd = toDatabase.collection.add_row()
rowToAdd.Matière = row.Matière
rowToAdd.Sujet = row.Sujet
rowToAdd.Done = row.Done
rowToAdd.Date = row.Date
deleteRow(row)
def deleteRow(row):
row.remove()
def checkAndMoveUrgentTask():
dateToday = datetime.today()
for row in cvListeTotale.collection.get_rows():
dateTaskNotion = datetime.strptime(row.Date.start.strftime("%Y-%m-%d"),"%Y-%m-%d")
dateMinusTwoDays = dateTaskNotion + timedelta(days=-2)
if dateToday >= dateMinusTwoDays:
switchRowFromDatabase(cvListeUrgente,row)
sendSms(row.Matière,row.Sujet,dateTaskNotion)
def sendSms(matiere,sujet,date):
sujetMessage = f"RAPPEL : Rendu à faire en {matiere}.\nSujet : \"{sujet}\".\nPour le {date}"
message = twilioClient.messages.create(body=sujetMessage, from_=twilioPhoneNumber, to=myPhoneNumber)
def checkAndMoveDoneTask():
for row in cvListeTotale.collection.get_rows():
if(row.Done == True):
switchRowFromDatabase(cvListeFinies,row)
if __name__ == "__main__":
checkAndMoveUrgentTask()
checkAndMoveDoneTask()