-
Notifications
You must be signed in to change notification settings - Fork 0
/
DBHandler.py
122 lines (109 loc) · 3.66 KB
/
DBHandler.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import datetime
from notion_client import Client
class DBHandler:
def __init__(self, notion_token: str):
self.notion_token = notion_token
self.notion = Client(auth=self.notion_token)
self.today = datetime.datetime.today()
def get_doing_task_db(self, db_id: str):
db = self.notion.databases.query(
**{
'database_id': db_id,
"filter": {
"and": [
{
"property": "期限",
"select": {
"does_not_equal": 'Done'
}
}
]
}
}
)
return db['results']
def get_done_task_db(self, db_id: str):
db = self.notion.databases.query(
**{
'database_id': db_id,
"filter": {
"and": [
{
"property": "期限",
"select": {
"equals": 'Done'
}
},
{
"property": "完了日時",
"date": {
"is_empty": True
}
}
]
}
}
)
return db['results']
def update_task_date(self, page_id: str) -> None:
today = str(datetime.datetime.now().isoformat())
self.notion.pages.update(
page_id,
properties={
'完了日時': {
'date': {
'start': today,
'time_zone': 'Asia/Tokyo'
}
}
}
)
def update_task_status(self, page_id: str, priority: str, deadline: str) -> None:
self.notion.pages.update(
page_id,
properties={
'Priority': {
'select': {
'name': priority
}
},
'期限': {
'select': {
'name': deadline
}
}
}
)
def get_task_priority(self, deadline_date) -> str:
# 3日以内の場合は、高
# 3日以上7日以内の場合は、中
# 7日以上の場合は、低
if deadline_date is None:
return '低'
if deadline_date <= self.today + datetime.timedelta(days=3):
return '高'
elif self.today + datetime.timedelta(days=3) < deadline_date <= self.today + datetime.timedelta(days=7):
return '中'
else:
return '低'
def get_task_deadline(self, deadline_date) -> str:
# 1日以内の場合は、dau
# 2日以上7日以内の場合は、week
# 7日以上の場合は、none
if deadline_date is None:
return 'none'
if deadline_date <= self.today + datetime.timedelta(days=1):
return 'day'
elif deadline_date <= self.today + datetime.timedelta(days=7):
return 'week'
else:
return 'none'
@staticmethod
def get_page_id(db_result) -> str:
return db_result['id']
@staticmethod
def get_task_deadline_date(db_result):
if db_result['properties']['期日']['date'] is None:
return None
else:
return datetime.datetime.strptime(db_result['properties']['期日']['date']['start'], '%Y-%m-%d')