-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnotion.py
44 lines (39 loc) · 1.25 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
import requests
import os
from datetime import datetime
class NotionExporter:
def post_notion(text_heading, text_content):
token = os.environ.get("NOTION_TOKEN")
url = "https://api.notion.com/v1/pages"
data = {
"parent": {"database_id": "1b9cbc3855e942e6b6ecf9bc0bde3a49"},
"properties": {
"Heading": {
"title": [
{
"text": {
"content": text_heading
}
}
]
},
"Content": {
"rich_text": [
{
"text": {
"content": text_content
}
}
]
}
}}
import json
data = json.dumps(data)
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/json",
"Notion-Version": "2022-02-22",
"Content-Type": "application/json"
}
response = requests.post(url, headers=headers, data=data)
print(response.text)