diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cf8c6d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +env +__pycache__ \ No newline at end of file diff --git a/dashboard.py b/dashboard.py deleted file mode 100644 index e62e05b..0000000 --- a/dashboard.py +++ /dev/null @@ -1,5 +0,0 @@ -''' -Class to generate a static website based on a csv file -''' -class Dashboard(): - pass \ No newline at end of file diff --git a/discourse.py b/discourse.py index a380b11..1e5c73e 100644 --- a/discourse.py +++ b/discourse.py @@ -24,14 +24,10 @@ class Discourse(): def category_topics_csv(self, category_id: str) -> requests.Response: """Save category topics to a csv file""" cat_data = self.get_category_data(category_id) - columns = ["id", "title", "tags", "url"] + columns = ["id", "title", "tags"] with open('zasoby.csv', 'w', encoding='UTF8') as f: write = csv.writer(f) write.writerow(columns) for topic in cat_data["topic_list"]["topics"]: - write.writerow([topic["id"], topic["title"], topic["tags"], f'{self.url}t/{topic["id"]}']) - - -if __name__=="__main__": - dis = Discourse("https://kb.hs3.pl/") - dis.category_topics_csv(9) \ No newline at end of file + html_url = f'{topic["title"]}' + write.writerow([topic["id"], html_url, topic["tags"]]) diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..ce05618 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,248 @@ + + + + + + Baza Zasobów Hackerspace Trójmiasto + + + + + + + + + + + +
+
+
+
+

Baza Zasobów Hackerspace Trójmiasto

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
idtitletags
45Jak stworzyć nowy wpis do bazy zasobów Hackerspace Trójmiasto?[]
20O kategorii: Baza Wiedzy Hackerspace'u[]
108PC Engines APU2 Router Box['cow-work', 'networking']
61HS3 BOFH['cow-work', 'garage', 'events', 'bofh']
93King Bob['cow-work']
92Drukarka 3D Creality K1 Max['tools', 'workshop', '3d-print']
91Drukarka 3D Creality Ender 3['tools', 'workshop', '3d-print']
90Chciejlista[]
85Komu powinien służyć Spejs[]
84Budżet[]
83Hackerspace Dragon Dreaming[]
82Biblioteka['cow-work', 'books']
66Apteczki['cow-work', 'garage', 'bhp']
44Brayton Power['garage', 'projects']
52Evil Submarine['cow-work', 'projects']
50Infinity mirror (duże)['garage', 'projects']
47Cricut Maker 3 ploter tnący['tools', 'workshop']
41Wiertarka PSB 500 RE BOSCH['garage', 'tools']
46What the Duck['cow-work', 'wled']
+
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/docs/static/css/style.css b/docs/static/css/style.css new file mode 100644 index 0000000..aa902ec --- /dev/null +++ b/docs/static/css/style.css @@ -0,0 +1,14 @@ +footer { + padding: 12px; + margin-top: auto; +} + +/* || Sidenav */ +.sidenav { + width: 250px; + position: sticky; + z-index: 1; + top: 0; + overflow-x: hidden; + padding: 6px 8px 6px 16px; +} \ No newline at end of file diff --git a/main.py b/main.py index f5aa226..892352f 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,36 @@ DISCOURSE_URL = "https://kb.hs3.pl/" # Database is hosted here DISCOURSE_CATEGORY = 9 # Database is stored in this Discourse category +import os, shutil +from jinja2 import Environment, FileSystemLoader +import pandas as pd + from discourse import Discourse -if __name__ == "__main__": - print(f"Discourse database: f{DISCOURSE_URL}/{DISCOURSE_CATEGORY}") - print("Fetching database data to zasoby.csv...") - dis = Discourse(DISCOURSE_URL) +def generate_dashboard(): + """Generate dashboard from zasoby.csv file""" + website_folder = "docs" + data = pd.read_csv("zasoby.csv") + env = Environment(loader=FileSystemLoader("template")) - print("Generating HTML dashboard...") + 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__": + print(f"Discourse database: {DISCOURSE_URL}{DISCOURSE_CATEGORY}") + print("Fetching database data to zasoby.csv") + dis = Discourse(DISCOURSE_URL) + dis.category_topics_csv(DISCOURSE_CATEGORY) + print("Generating HTML dashboard") + generate_dashboard() print("Done!") \ No newline at end of file diff --git a/template/_base_template.html b/template/_base_template.html new file mode 100644 index 0000000..10b53c2 --- /dev/null +++ b/template/_base_template.html @@ -0,0 +1,33 @@ + + + + + + Baza Zasobów Hackerspace Trójmiasto + + + + + + + + + + + {% block body %}{% endblock body %} + + + + + + + + + diff --git a/template/_main_layout.html b/template/_main_layout.html new file mode 100644 index 0000000..b2be738 --- /dev/null +++ b/template/_main_layout.html @@ -0,0 +1,28 @@ +{% extends "_base_template.html" %} {% block body %} +
+
+
{% block sidenav %}{% endblock sidenav %}
+
+

Baza Zasobów Hackerspace Trójmiasto

+ + + + {% for cell in t_header %} + + {% endfor %} + + + + {% for row in t_body %} + + {% for cell in row %} + + {% endfor %} + + {% endfor %} + +
{{cell}}
{{cell}}
+
+
+
+{% endblock body %} diff --git a/template/static/css/style.css b/template/static/css/style.css new file mode 100644 index 0000000..aa902ec --- /dev/null +++ b/template/static/css/style.css @@ -0,0 +1,14 @@ +footer { + padding: 12px; + margin-top: auto; +} + +/* || Sidenav */ +.sidenav { + width: 250px; + position: sticky; + z-index: 1; + top: 0; + overflow-x: hidden; + padding: 6px 8px 6px 16px; +} \ No newline at end of file diff --git a/zasoby.csv b/zasoby.csv index 5940327..86ee055 100644 --- a/zasoby.csv +++ b/zasoby.csv @@ -1,20 +1,20 @@ -id,title,tags,url -45,Jak stworzyć nowy wpis do bazy zasobów Hackerspace Trójmiasto?,[],https://kb.hs3.pl/t/45 -20,O kategorii: Baza Wiedzy Hackerspace'u,[],https://kb.hs3.pl/t/20 -108,PC Engines APU2 Router Box,"['cow-work', 'networking']",https://kb.hs3.pl/t/108 -61,HS3 BOFH,"['cow-work', 'garage', 'events', 'bofh']",https://kb.hs3.pl/t/61 -93,King Bob,['cow-work'],https://kb.hs3.pl/t/93 -92,Drukarka 3D Creality K1 Max,"['tools', 'workshop', '3d-print']",https://kb.hs3.pl/t/92 -91,Drukarka 3D Creality Ender 3,"['tools', 'workshop', '3d-print']",https://kb.hs3.pl/t/91 -90,Chciejlista,[],https://kb.hs3.pl/t/90 -85,Komu powinien służyć Spejs,[],https://kb.hs3.pl/t/85 -84,Budżet,[],https://kb.hs3.pl/t/84 -83,Hackerspace Dragon Dreaming,[],https://kb.hs3.pl/t/83 -82,Biblioteka,"['cow-work', 'books']",https://kb.hs3.pl/t/82 -66,Apteczki,"['cow-work', 'garage', 'bhp']",https://kb.hs3.pl/t/66 -44,Brayton Power,"['garage', 'projects']",https://kb.hs3.pl/t/44 -52,Evil Submarine,"['cow-work', 'projects']",https://kb.hs3.pl/t/52 -50,Infinity mirror (duże),"['garage', 'projects']",https://kb.hs3.pl/t/50 -47,Cricut Maker 3 ploter tnący,"['tools', 'workshop']",https://kb.hs3.pl/t/47 -41,Wiertarka PSB 500 RE BOSCH,"['garage', 'tools']",https://kb.hs3.pl/t/41 -46,What the Duck,"['cow-work', 'wled']",https://kb.hs3.pl/t/46 +id,title,tags +45,"Jak stworzyć nowy wpis do bazy zasobów Hackerspace Trójmiasto?",[] +20,"O kategorii: Baza Wiedzy Hackerspace'u",[] +108,"PC Engines APU2 Router Box","['cow-work', 'networking']" +61,"HS3 BOFH","['cow-work', 'garage', 'events', 'bofh']" +93,"King Bob",['cow-work'] +92,"Drukarka 3D Creality K1 Max","['tools', 'workshop', '3d-print']" +91,"Drukarka 3D Creality Ender 3","['tools', 'workshop', '3d-print']" +90,"Chciejlista",[] +85,"Komu powinien służyć Spejs",[] +84,"Budżet",[] +83,"Hackerspace Dragon Dreaming",[] +82,"Biblioteka","['cow-work', 'books']" +66,"Apteczki","['cow-work', 'garage', 'bhp']" +44,"Brayton Power","['garage', 'projects']" +52,"Evil Submarine","['cow-work', 'projects']" +50,"Infinity mirror (duże)","['garage', 'projects']" +47,"Cricut Maker 3 ploter tnący","['tools', 'workshop']" +41,"Wiertarka PSB 500 RE BOSCH","['garage', 'tools']" +46,"What the Duck","['cow-work', 'wled']"