vanten-s.com/main.py

51 lines
1.6 KiB
Python
Raw Normal View History

2023-08-05 10:42:22 +02:00
import frmWrk.website as website
2023-08-04 16:40:47 +02:00
import feed_generator
2023-09-05 15:22:39 +02:00
import pathlib
2023-08-05 10:42:22 +02:00
from time import sleep
2023-08-04 16:40:47 +02:00
2023-09-06 11:00:25 +02:00
article_base_html = ""
with open("src/article.html") as article_html:
article_base_html = article_html.read()
articles_base_html = ""
with open("src/articles.html") as articles_html:
articles_base_html = articles_html.read()
def article_list():
article_paths = (pathlib.Path.cwd() / "feed_articles").glob("[0-9]*")
article_paths_sorted = sorted(article_paths, key=lambda x: x.name, reverse=True)
metadatas = [feed_generator.convert_markdown_to_html(path)[1] for path in article_paths_sorted]
elements = ['<li><a href="articles.html?{guid}">{title} ({guid})</a></li>'.format(title=metadata["title"][0], guid=metadata["guid"][0]) for metadata in metadatas]
return articles_base_html.format(elements="\n".join(elements))
2023-09-05 15:22:39 +02:00
def article(path):
2023-09-06 11:00:25 +02:00
if not "?" in path:
return article_list()
2023-09-05 15:22:39 +02:00
article_name = path.split("?")[1]
article_html = feed_generator.convert_markdown_to_html(pathlib.Path("feed_articles") / article_name)
2023-09-06 11:00:25 +02:00
return article_base_html.format(body=article_html[0])
2023-09-05 15:22:39 +02:00
2023-09-06 11:00:25 +02:00
if __name__ == "__main__":
webserver = website.WebServer("", 3000, "./src", overwrites={"/articles.html": article})
2023-08-01 21:04:58 +02:00
2023-09-06 11:00:25 +02:00
webserver.start()
2023-08-01 21:04:58 +02:00
2023-09-06 11:00:25 +02:00
while True:
feed = feed_generator.make_rss_feed("feed_articles", "Vantens", "https://vanten-s.com/", "Vantens personal feed")
with open("src/rss.xml", "w") as f:
f.write(feed)
2023-08-05 10:42:22 +02:00
2023-09-06 11:00:25 +02:00
try:
sleep(15)
2023-08-05 10:42:22 +02:00
2023-09-06 11:00:25 +02:00
except KeyboardInterrupt:
break
2023-08-05 10:42:22 +02:00
2023-09-06 11:00:25 +02:00
webserver.close()
2023-08-05 10:42:22 +02:00