-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotion_setup.py
More file actions
49 lines (38 loc) · 1.12 KB
/
notion_setup.py
File metadata and controls
49 lines (38 loc) · 1.12 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
import os
import re
from dotenv import load_dotenv
from notion_client import Client
load_dotenv()
notion = Client(auth=os.getenv("NOTION_API_KEY"))
database_id = os.getenv("NOTION_DB_ID") or os.getenv("NOTION_DATABASE_ID")
def sanitize_select_option(value):
if not value:
return None
cleaned = value.replace(",", " ")
cleaned = re.sub(r"\s+", " ", cleaned).strip()
return cleaned[:100] or None
def create_task(title, due_date=None, subject=None, description=None, priority="Medium"):
properties = {
"Name": {
"title": [{"text": {"content": title}}],
},
"Status": {
"status": {"name": "Not started"},
},
"Priority": {
"select": {"name": priority},
},
}
if due_date:
properties["Due Date"] = {
"date": {"start": due_date},
}
subject = sanitize_select_option(subject)
if subject:
properties["Subject"] = {
"select": {"name": subject},
}
return notion.pages.create(
parent={"database_id": database_id},
properties=properties,
)