aboutsummaryrefslogtreecommitdiff
path: root/blog/generate_html.py
diff options
context:
space:
mode:
authornathansmith117 <nathansmith@posteo.com>2025-03-30 21:50:32 -0600
committernathansmith117 <nathansmith@posteo.com>2025-03-30 21:50:32 -0600
commit61cbae386b256bb6adb0adaa52cd00585a0820e2 (patch)
tree90a430ea7308d35d16d918bac398342f0bfe03bc /blog/generate_html.py
parent45aaca33b67b1dc764b199a9e4c3aebf4892c2a7 (diff)
Made blogging system better
Diffstat (limited to 'blog/generate_html.py')
-rwxr-xr-xblog/generate_html.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/blog/generate_html.py b/blog/generate_html.py
new file mode 100755
index 0000000..7360fa3
--- /dev/null
+++ b/blog/generate_html.py
@@ -0,0 +1,59 @@
+#! /usr/bin/python3
+
+"""
+A script to generate html from the rss feed
+"""
+
+import xml.etree.ElementTree as et
+
+# Generates a html table for the article
+# I use table layout because fuck you
+def make_article_table(article_info, article):
+ return """
+ <table border="1" width="60%">
+ <tr><td><h2 id=\"{name}\">{title}</h2>--- {date}</td></tr>
+ <tr><td>{article}</td></tr>
+ </table>
+ """.format(
+ name=article_info["name"],
+ title=article_info["title"],
+ date=article_info["pubDate"],
+ article=article
+ )
+
+def main():
+ tree = et.parse("articles.xml")
+ root = tree.getroot()
+
+ template = ""
+
+ # Open html template
+ with open("template.html", "r") as fp:
+ template = fp.read()
+
+ article_html = ""
+
+ # Get articles from rss
+ for item in root:
+ article_info = {
+ "title": item.find("title").text,
+ "name": item.find("name").text,
+ "pubDate": item.find("pubDate").text
+ }
+
+ article = ""
+
+ with open(item.find("file").text, "r") as fp:
+ article = fp.read()
+
+ # Remove article tags.
+ article = article[article.find("<article>")+9::]
+ article = article[:article.find("</article>"):]
+ article_html += make_article_table(article_info, article)
+
+ # Format the articles into the html
+ template = template.format(articles=article_html)
+ print(template)
+
+if __name__ == "__main__":
+ main()