Skip to content

Commit d5805ee

Browse files
committed
Creating file and writing basic function
1 parent d89bdd5 commit d5805ee

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

__init__.py

Whitespace-only changes.

data.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"object": "list",
3+
"results": [{
4+
"object": "block",
5+
"id": "e42cdf2c-ef06-4059-b88c-2b159415c902",
6+
"created_time": "2022-02-14T21:40:00.000Z",
7+
"last_edited_time": "2022-02-14T21:40:00.000Z",
8+
"has_children": false,
9+
"archived": false,
10+
"type": "embed",
11+
"embed": {
12+
"caption": [
13+
14+
],
15+
"url": "https://twitter.com/ZeratoR/status/1493276555052826624?s=20&t=UFnSjZGiFRcZQ9lHUv0JtA"
16+
}
17+
},
18+
{
19+
"object": "block",
20+
"id": "a8571a10-b277-44e4-8b7a-a290d1deed1d",
21+
"created_time": "2022-02-14T22:56:00.000Z",
22+
"last_edited_time": "2022-02-14T22:58:00.000Z",
23+
"has_children": false,
24+
"archived": false,
25+
"type": "paragraph",
26+
"paragraph": {
27+
"text": [{
28+
"type": "text",
29+
"text": {
30+
"content": "Permission",
31+
"link": "None"
32+
},
33+
"annotations": {
34+
"bold": false,
35+
"italic": false,
36+
"strikethrough": false,
37+
"underline": false,
38+
"code": false,
39+
"color": "default"
40+
},
41+
"plain_text": "Permission",
42+
"href": "None"
43+
}]
44+
}
45+
}
46+
],
47+
"next_cursor": "None",
48+
"has_more": false
49+
}

main.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import requests
2+
import json
3+
import os
4+
5+
token = os.environ["NOTION_TOKEN_PUT"]
6+
7+
block_id = 'e42cdf2c-ef06-4059-b88c-2b159415c902'
8+
block_page_id = 'fa2142e7178a4af980ef0bc2bcde14ec'
9+
10+
url_block_page = f"https://api.notion.com/v1/blocks/{block_page_id}/children"
11+
url = f"https://api.notion.com/v1/blocks/{block_id}"
12+
13+
headers = {
14+
"Accept": "application/json",
15+
"Notion-Version": "2021-08-16",
16+
"Content-Type": "application/json",
17+
"Authorization": "Bearer " + token
18+
}
19+
20+
21+
def main():
22+
23+
#print(updateEmbed())
24+
25+
print(appendEmbed())
26+
27+
# Appel de l'ensemble des blocks de la page via l'id de page
28+
29+
def apiCall():
30+
31+
response = requests.request("GET", url_block_page, headers=headers)
32+
33+
return json.loads(response.text)
34+
35+
#Met à jour le lien du tweet dans le block "embed" via son id (block_id)
36+
37+
def updateEmbed():
38+
39+
updateData = {
40+
"embed":{
41+
"url":"https://twitter.com/NotionAPI/status/1430576039650942976?s=20&t=R92L0tBPzRXD42TS-Yyalw"
42+
}
43+
}
44+
45+
return requests.request("PATCH", url, json=updateData, headers=headers)
46+
47+
#Créer un nouveau block "embed" qui contient le lien vers le tweet
48+
49+
def appendEmbed():
50+
51+
appData = [{
52+
"object": "block",
53+
"type": "embed",
54+
"embed": {
55+
"url": "https://twitter.com/ZeratoR/status/1493276555052826624?s=20&t=UFnSjZGiFRcZQ9lHUv0JtA"
56+
}
57+
}
58+
]
59+
60+
return requests.request("PATCH", url_block_page, json={"children": appData}, headers=headers)
61+
62+
63+
if __name__ == '__main__':
64+
main()

0 commit comments

Comments
 (0)