hs3-baza-zasobow-dashboard/main.py

28 lines
1 KiB
Python
Raw Normal View History

2026-01-11 18:33:53 +01:00
import os, shutil
from jinja2 import Environment, FileSystemLoader
import pandas as pd
2026-01-11 19:25:04 +01:00
from discourse import DiscourseDatabase
2026-01-11 18:33:53 +01:00
def generate_dashboard():
"""Generate dashboard from zasoby.csv file"""
2026-01-11 19:25:04 +01:00
print("Generating HTML dashboard")
2026-01-11 18:33:53 +01:00
website_folder = "docs"
data = pd.read_csv("zasoby.csv")
env = Environment(loader=FileSystemLoader("template"))
2026-01-11 19:25:04 +01:00
print("Removing old website files")
2026-01-11 18:33:53 +01:00
shutil.rmtree(f"./{website_folder}")
os.mkdir(f"./{website_folder}")
2026-01-11 19:25:04 +01:00
print("Creating a new website")
2026-01-11 18:33:53 +01:00
shutil.copytree("template/static", f"{website_folder}/static")
template = env.get_template("_main_layout.html")
with open(f"{website_folder}/index.html", "w+", encoding="utf-8") as file:
header_row = data.columns.values.tolist()
rows = data.values.tolist()
html = template.render(title="Baza Zasobów Hackerspace Trójmiasto", t_header=header_row, t_body=rows)
file.write(html)
if __name__ == "__main__":
2026-01-11 19:25:04 +01:00
DiscourseDatabase()
2026-01-11 18:33:53 +01:00
generate_dashboard()
print("Done!")