Skip to content
Snippets Groups Projects
Commit 96eb4942 authored by VALLET Nathan's avatar VALLET Nathan
Browse files

add preview of html page generation

parent a97bb08f
No related branches found
No related tags found
No related merge requests found
import feedparser
from urllib.parse import urlparse
from datetime import datetime
import time
def charge_urls(liste_url: list[str]) -> list[dict[str, any] | None]:
# if the key 'bozo' is true, then the feed had an error during processing, so we set it to None
......@@ -31,7 +33,33 @@ def fusion_flux(liste_url: list[str], liste_flux: list[dict[str, any] | None],
return feeds
def genere_html(liste_evenements: list[dict[str, str]],
chemin_html: str) -> None:
output = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><title>Events log</title><link rel=\"stylesheet\" href=\"css/feed.css\" type=\"text/css\"/></head><body><article><header><h1>Events log</h1></header>"
output += f"<p>{time.asctime()}</p>"
for evenement in liste_evenements:
output += "<article><header>"
output += f"<h2>{evenement['titre']}</h2>"
output += "</header>"
output += f"<p>from: {evenement['serveur']}</p>"
output += f"<p>{evenement['date_publi']}</p>"
output += f"<p>{evenement['categorie']}</p>"
output += f"<p>{evenement['guid']}</p>"
output += f"<p><a href=\"{evenement['lien']}\">{evenement['lien']}</a></p>"
output += f"<p>{evenement['description']}</p>"
output += "</article>"
output += "</article></body></html>"
with open(chemin_html, "w") as outputfile:
outputfile.write(output)
def main():
raise NotImplementedError
urls = [f"http://192.168.78.{i}/rss.xml" for i in range(3, 15)]
charge = charge_urls(urls)
evenements = fusion_flux(urls, charge, None)
print(evenements)
genere_html(evenements, "aggreg.html")
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment