hs3-baza-zasobow-dashboard/main.py

36 lines
1.3 KiB
Python
Raw Normal View History

DISCOURSE_URL = "https://kb.hs3.pl/" # Database is hosted here
DISCOURSE_CATEGORY = 9 # Database is stored in this Discourse category
2026-01-11 18:33:53 +01:00
import os, shutil
from jinja2 import Environment, FileSystemLoader
import pandas as pd
from discourse import Discourse
2026-01-11 18:33:53 +01:00
def generate_dashboard():
"""Generate dashboard from zasoby.csv file"""
website_folder = "docs"
data = pd.read_csv("zasoby.csv")
env = Environment(loader=FileSystemLoader("template"))
shutil.rmtree(f"./{website_folder}")
os.mkdir(f"./{website_folder}")
shutil.copytree("template/static", f"{website_folder}/static")
print("Creating page to static file.")
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 18:33:53 +01:00
print(f"Discourse database: {DISCOURSE_URL}{DISCOURSE_CATEGORY}")
print("Fetching database data to zasoby.csv")
dis = Discourse(DISCOURSE_URL)
2026-01-11 18:33:53 +01:00
dis.category_topics_csv(DISCOURSE_CATEGORY)
print("Generating HTML dashboard")
generate_dashboard()
print("Done!")