-
Notifications
You must be signed in to change notification settings - Fork 1
/
Notion_Update_v4.0.py
57 lines (42 loc) · 1.52 KB
/
Notion_Update_v4.0.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
# coding=utf-8
import os
from Util.FeedTool import NotionAPI, parse_rss_entries
import requests
# 从环境变量中获取Notion API信息
NOTION_API_KEY = os.getenv('NOTION_API_KEY')
NOTION_READING_DATABASE_ID = os.getenv('NOTION_READING_DATABASE_ID')
NOTION_URL_DATABASE_ID = os.getenv('NOTION_URL_DATABASE_ID')
def update():
if NOTION_API_KEY is None:
print("NOTION_SEC secrets is not set!")
return
api = NotionAPI(NOTION_API_KEY, NOTION_READING_DATABASE_ID, NOTION_URL_DATABASE_ID)
rss_feed_list = api.queryFeed_from_notion()
for rss_feed in rss_feed_list:
feeds, entries = parse_rss_entries(rss_feed.get("url"))
rss_page_id = rss_feed.get("page_id")
if len(entries) == 0:
api.saveFeed_to_notion(feeds, page_id=rss_page_id)
continue
# Check for Repeat Entries
url=f"{api.NOTION_API_database}/{api.reader_id}/query"
payload = {
"filter": {
"property": "Source",
"relation": {"contains": rss_page_id},
},
}
response = requests.post(url=url, headers=api.headers, json=payload)
current_urls = [x.get("properties").get("URL").get("url") for x in response.json().get("results")]
repeat_flag = 0
rss_tags = rss_feed.get("tags")
api.saveFeed_to_notion(feeds, page_id=rss_page_id)
for entry in entries:
if entry.get("link") not in current_urls:
api.saveEntry_to_notion(entry, rss_page_id, rss_tags)
current_urls += [entry.get("link")]
else:
repeat_flag += 1
print(f"读取到 {len(entries)} 篇内容,其中重复 {repeat_flag} 篇。")
if __name__ == "__main__":
update()