2026-01-11 15:56:30 +01:00
|
|
|
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
|
|
|
|
|
|
2026-01-11 15:56:30 +01:00
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
|
2026-01-11 15:56:30 +01:00
|
|
|
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")
|
2026-01-11 15:56:30 +01:00
|
|
|
dis = Discourse(DISCOURSE_URL)
|
2026-01-11 18:33:53 +01:00
|
|
|
dis.category_topics_csv(DISCOURSE_CATEGORY)
|
|
|
|
|
print("Generating HTML dashboard")
|
|
|
|
|
generate_dashboard()
|
2026-01-11 15:56:30 +01:00
|
|
|
print("Done!")
|