kindlerss.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from lxml import etree
  2. import urllib.request
  3. import os
  4. from argparse import ArgumentParser
  5. parser = ArgumentParser()
  6. parser.add_argument("url", type=str)
  7. parser.add_argument("output", type=str)
  8. args = parser.parse_args()
  9. URL = args.url
  10. DIR = args.output
  11. if not os.path.exists(DIR):
  12. os.makedirs(DIR)
  13. os.makedirs(os.path.join(DIR, "articles"))
  14. FILE = open(os.path.join(DIR, "index.html"), "w")
  15. print("<html>", file=FILE)
  16. print("<head>", file=FILE)
  17. print("<meta charset=\"UTF-8\">", file=FILE)
  18. print("<title>RSS Feed</title>", file=FILE)
  19. print("<style>", file=FILE)
  20. print("* { font-family: sans-serif; line-height: 1.6em;}", file=FILE)
  21. print("a:link { color: black }", file=FILE)
  22. print("a:visited { color: #888 }", file=FILE)
  23. print("</style>", file=FILE)
  24. print("</head>", file=FILE)
  25. print("<bady>", file=FILE)
  26. print("<h1>RSS Feed</h1>", file=FILE)
  27. print("<ul>", file=FILE)
  28. feed = urllib.request.urlopen("https://finetuned.nl/freshrss/p/i/?a=rss&rid=610659e817a51&hours=168")
  29. feed = etree.parse(feed)
  30. feed = feed.getroot()
  31. channel = feed.find("channel")
  32. for item in channel.iterfind("item"):
  33. title = item.find("title").text
  34. guid = item.find("guid").text
  35. contents = item.find("description").text
  36. print(f"<li><a href=\"articles/{guid}.html\">{title}</a></li>", file=FILE)
  37. with open(os.path.join(DIR, "articles", f"{guid}.html"), "w") as file:
  38. print("<html>", file=file)
  39. print("<head>", file=file)
  40. print("<meta charset=\"UTF-8\">", file=file)
  41. print("<title>RSS Feed</title>", file=file)
  42. print("</head>", file=file)
  43. print("<bady>", file=file)
  44. print(contents, file=file)
  45. print("</body>", file=file)
  46. print("</html>", file=file)
  47. print("</ul>", file=FILE)
  48. print("</body>", file=FILE)
  49. print("</html>", file=FILE)
  50. FILE.close()