1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- from lxml import etree
- import urllib.request
- import os
- from argparse import ArgumentParser
- parser = ArgumentParser()
- parser.add_argument("url", type=str)
- parser.add_argument("output", type=str)
- args = parser.parse_args()
- URL = args.url
- DIR = args.output
- if not os.path.exists(DIR):
- os.makedirs(DIR)
- os.makedirs(os.path.join(DIR, "articles"), exist_ok=True)
- FILE = open(os.path.join(DIR, "index.html"), "w")
- print("<html>", file=FILE)
- print("<head>", file=FILE)
- print("<meta charset=\"UTF-8\">", file=FILE)
- print("<title>RSS Feed</title>", file=FILE)
- print("<style>", file=FILE)
- print("* { font-family: sans-serif; line-height: 1.6em;}", file=FILE)
- print("a:link { color: black }", file=FILE)
- print("a:visited { color: #888 }", file=FILE)
- print("</style>", file=FILE)
- print("</head>", file=FILE)
- print("<bady>", file=FILE)
- print("<h1>RSS Feed</h1>", file=FILE)
- print("<ul>", file=FILE)
- feed = urllib.request.urlopen("https://finetuned.nl/freshrss/p/i/?a=rss&rid=610659e817a51&hours=168")
- feed = etree.parse(feed)
- feed = feed.getroot()
- channel = feed.find("channel")
- for item in channel.iterfind("item"):
- title = item.find("title").text
- guid = item.find("guid").text
- contents = item.find("description").text
- print(f"<li><a href=\"articles/{guid}.html\">{title}</a></li>", file=FILE)
- with open(os.path.join(DIR, "articles", f"{guid}.html"), "w") as file:
- print("<html>", file=file)
- print("<head>", file=file)
- print("<meta charset=\"UTF-8\">", file=file)
- print("<title>RSS Feed</title>", file=file)
- print("<style>", file=FILE)
- print("* { font-family: sans-serif; line-height: 1.6em;}", file=FILE)
- print("a:link { color: black }", file=FILE)
- print("a:visited { color: #888 }", file=FILE)
- print("</style>", file=FILE)
- print("</head>", file=file)
- print("<bady>", file=file)
- print(contents, file=file)
- print("</body>", file=file)
- print("</html>", file=file)
- print("</ul>", file=FILE)
- print("</body>", file=FILE)
- print("</html>", file=FILE)
- FILE.close()
|