-
Notifications
You must be signed in to change notification settings - Fork 4
/
notion.py
51 lines (47 loc) · 955 Bytes
/
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
import os
from datetime import datetime
from notion_client import Client
nc = Client(auth=os.getenv("NOTION_API_KEY"))
root_page = 'af999b3e02e0402e9698ddc4bcf81729'
def create_notion_page(title, content, emoji = "📔", heading = "Summary"):
# Create a new page in the specified database
page_data = {
"parent": { "page_id": root_page },
"icon": {
"emoji": emoji
},
"properties": {
"title": [
{
"text": {
"content": title
}
}
],
},
"children": [
# {
# "object": "block",
# "type": "heading_2",
# "heading_2": {
# "rich_text": [{ "type": "text", "text": { "content": heading } }]
# }
# },
{
"object": "block",
"type": "paragraph",
"paragraph": {
"rich_text": [
{
"type": "text",
"text": {
"content": content,
}
}
]
}
}
]
}
new_page = nc.pages.create(**page_data)
print("New page created with ID:", new_page["id"])