-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
66 lines (53 loc) · 1.92 KB
/
main.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
from feedgenerator import SyndicationFeed
from recipes import get_recipes
from cooker import Cooker
import fire
from util import url_to_valid_filename, put_github_action_env, xml_escape
all_feed_files = set()
def main(repository: str, repository_owner: str, limit=20):
recipes = get_recipes()
json_feeds = []
atom_feeds = []
for name in recipes:
normalized_name = url_to_valid_filename(name)
cooker = Cooker(
name=name,
normalized_name=normalized_name,
repository=repository,
repository_owner=repository_owner,
recipe=recipes[name],
limit=recipes[name].get("limit", limit),
)
json_feed, atom_feed = cooker.cook()
json_feeds.append(json_feed)
atom_feeds.append(atom_feed)
write_to_file(f"{normalized_name}.json", json_feed)
write_to_file(f"{normalized_name}.xml", atom_feed)
generate_opml(json_feeds, "all_opml_with_json_feed.xml")
generate_opml(atom_feeds, "all_opml_with_atom_feed.xml")
put_github_action_env("FEED_FILES", "\n".join(all_feed_files))
def generate_opml(feeds: [SyndicationFeed], path: str):
all_feed_files.add(path)
with open(path, 'w') as f:
f.write("""<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
<head>
<title>Feed Cooker</title>
</head>
<body>
""")
f.write("""<outline title="Cooker" text="Cooker">\n""")
for feed in feeds:
url = xml_escape(feed.feed["feed_url"])
title = xml_escape(feed.feed["title"])
f.write(
f""" <outline text="{title}" type="rss" xmlUrl="{url}" title="{title}"/>\n""")
f.write("</outline>\n")
f.write("</body>\n")
f.write("</opml>\n")
def write_to_file(path: str, feed: SyndicationFeed):
all_feed_files.add(path)
with open(path, "w") as f:
feed.write(f, "utf-8")
if __name__ == "__main__":
fire.Fire(main)