forked from CR0ZER/rss-flow-py-to-notion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeed_to_notion.py
57 lines (46 loc) · 2.15 KB
/
feed_to_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
52
53
54
55
56
57
###########################################
# This project have been created by @CR0ZER
# https://github.com/CR0ZER/
###########################################
from utils.utils import Tools, Notion
import feedparser
if __name__ == "__main__":
links_with_tags = Tools.get_rss_links_with_tags("rss_links.json")
notion, database_id = Notion.make_notion_connection()
feedparser.USER_AGENT = "feedparser/6.0.11 +https://github.com/kurtmckee/feedparser/"
if notion and database_id:
for link_, tag_ in links_with_tags:
try:
feed = feedparser.parse(link_)
if feed.entries.__len__() == 0:
print(f"[ERROR] No entries found for link: {link_}")
continue
for entry in feed.entries:
title = entry.title
author = entry.author
tag = tag_
date = Tools.format_date(entry.published)
link = entry.link
content = entry.content[0].value if hasattr(entry, "content") else entry.summary
if hasattr(entry, "content"):
content = entry.content[0].value
content_type = "Full article"
else:
content = entry.summary
content_type = "Summary"
if not Notion.does_page_exist(notion, database_id, title) and Tools.is_date_younger_than_week(date):
Notion.create_notion_page(
notion=notion,
database_id=database_id,
title=title,
author=author,
tag=tag,
article_date=date,
link=link,
content=content,
content_type=content_type
)
except:
print("[ERROR] Error while parsing for link: ", link)
continue
Notion.archive_old_pages(notion, database_id)