diff options
author | nathansmith117 <nathansmith@posteo.com> | 2025-03-29 05:52:09 -0600 |
---|---|---|
committer | nathansmith117 <nathansmith@posteo.com> | 2025-03-29 05:52:09 -0600 |
commit | 064e0fd8c82b8e34f27090e5a77ac55940a283c5 (patch) | |
tree | 08f5556ae1a90e3fdc05e8c0e388ec9f1cf5d545 /blog/generate.py | |
parent | 0c2c40c76f78cf8807d49e3aa77b6aa9fa151fe6 (diff) |
Working on blog
Diffstat (limited to 'blog/generate.py')
-rwxr-xr-x | blog/generate.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/blog/generate.py b/blog/generate.py index 3471ef9..09c2320 100755 --- a/blog/generate.py +++ b/blog/generate.py @@ -6,6 +6,24 @@ 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): + html_text = """ + <table border="1" width="60%"> + <tr><td><h2>{title}</h2>--- {date}</td></tr> + <tr><td>{article}</td></tr> + </table> + """ + + html_text = html_text.format( + title=article_info["title"], + date=article_info["pubDate"], + article=article + ) + + return html_text + def main(): tree = et.parse("feed.xml") root = tree.getroot() @@ -17,14 +35,25 @@ def main(): with open("template.html", "r") as fp: template = fp.read() + article_html = "" + # Get articles from rss for item in channel.findall("item"): + article_info = { + "title": item.find("title").text, + "pubDate": item.find("pubDate").text + } + article = item.find("description").text # Remove article tags. article = article[article.find("<article>")+9::] article = article[:article.find("</article>"):] - print(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() |