import os, re, shutil from jinja2 import Environment, FileSystemLoader import pandas as pd def add_download_button(row): item_id = re.sub(r' {item_id}' ) print_button = f'' return row + [download_button, print_button] def generate_dashboard(): """Generate dashboard from zasoby.csv file""" print("Generating HTML dashboard") website_folder = "fegen/docs" data = pd.read_csv("zasoby.csv") env = Environment(loader=FileSystemLoader("fegen/template")) print("Removing old website files") print("Creating a new website") shutil.copytree("fegen/template/static", f"{website_folder}/static", dirs_exist_ok=True) 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() + ["label", "print"] rows = map( add_download_button, 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__": from discourse import DiscourseDatabase DiscourseDatabase() generate_dashboard() print("Done!")