#! /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 """
{title}--- {date} |
{article} |
""".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_list = "\n"
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("")+9::]
article = article[:article.find(""):]
# Add article table to html
article_html += make_article_table(article_info, article)
# Add article to list.
article_list += \
f"- {article_info["title"]}
\n"
article_list += "
"
# Format the articles into the html
template = template.format(article_list=article_list, articles=article_html)
print(template)
if __name__ == "__main__":
main()