-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathold.py
136 lines (120 loc) · 5.05 KB
/
old.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# def createPage(databaseID, headers, page_name, summary, url, sections, language):
# """crea una página en una database de notion y pobla la página con los datos del artículo de wikipedia"""
# resumen, categoria, tags = get_summary(page_name, summary, language)
# createUrl = 'https://api.notion.com/v1/pages'
# newPageData = {
# "parent": { "database_id": databaseID },
# "object": "page",
# "properties": {
# "Title": {
# "title": [
# {
# "text": {
# "content": page_name
# }
# }
# ]
# },
# "Tags": {
# "multi_select":[
# ]
# },
# "Category": {
# "select": {
# "name": categoria
# }
# },
# "Reviewed": {
# "checkbox": False
# },
# "URL": {
# "url": url
# },
# "Lan": {
# "select": {
# "name": str.upper(language)
# }
# },
# }
# }
# for tag in tags:
# newPageData["properties"]["Tags"]["multi_select"].append({"name": tag})
# data = json.dumps(newPageData)
# res_insert = requests.request("POST", createUrl, headers=headers, data=data)
# newPageID = json.loads(res_insert.content)["id"]
# newPageData = {
# "children": [
# {
# "object": "block",
# "type": "heading_1",
# "heading_1": {
# "rich_text": [
# {
# "type": "text",
# "text": {
# "content": page_name
# }
# }
# ]
# }
# },
# {
# "object": "block",
# "type": "paragraph",
# "paragraph": {
# "rich_text": [
# {
# "type": "text",
# "text": {
# "content": resumen
# }
# }
# ]
# }
# }
# ]
# }
# excluded_titles = ['Referencias', 'Véase también', 'Enlaces externos', 'Fuentes', 'Notas', 'Bibliografía', 'Notes', 'References', 'External links', 'See also', 'Further reading' ,'Sources']
# for section in sections:
# if section.title not in excluded_titles:
# newPageData["children"].append({
# "object": "block",
# "type": "heading_2",
# "heading_2": {
# "rich_text": [
# {
# "type": "text",
# "text": {
# "content": section.title
# }
# }
# ]
# }
# })
# newPageData["children"].append({
# "object": "block",
# "type": "paragraph",
# "paragraph": {
# "rich_text": [
# {
# "type": "text",
# "text": {
# "content": get_section_summary(page_name, section.full_text, language)
# }
# }
# ]
# }
# })
# data = json.dumps(newPageData)
# updateURL = f'https://api.notion.com/v1/blocks/{newPageID}/children'
# res_update = requests.request("PATCH", updateURL, headers=headers, data=data)
# # return res_update.status_code, res_insert.status_code
# return str(res_insert.status_code) + " " + str(res_update.status_code)
# def flow_to_notion(page_name, headers, lan='en'):
# """Función que ejecuta el flujo completo para importar una página de wikipedia a Notion"""
# page_name, exists, summary, url, sections = import_wiki_page(page_name, lan)
# if exists:
# result = createPage(notion_database_id, headers, page_name, summary, url, sections, lan)
# else:
# result = "No existe la página"
# return result