kindlerss.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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"), exist_ok=True)
  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("<style>", file=FILE)
  43. print("* { font-family: sans-serif; line-height: 1.6em;}", file=FILE)
  44. print("a:link { color: black }", file=FILE)
  45. print("a:visited { color: #888 }", file=FILE)
  46. print("</style>", file=FILE)
  47. print("</head>", file=file)
  48. print("<bady>", file=file)
  49. print(contents, file=file)
  50. print("</body>", file=file)
  51. print("</html>", file=file)
  52. print("</ul>", file=FILE)
  53. print("</body>", file=FILE)
  54. print("</html>", file=FILE)
  55. FILE.close()