Simplify, add initial website

This commit is contained in:
Marta Sienkiewicz 2026-01-11 18:33:53 +01:00
parent 1b2ca8eb87
commit da95985e43
10 changed files with 391 additions and 37 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
env
__pycache__

View file

@ -1,5 +0,0 @@
'''
Class to generate a static website based on a csv file
'''
class Dashboard():
pass

View file

@ -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)
html_url = f'<a href="{self.url}t/{topic["id"]}">{topic["title"]}</a>'
write.writerow([topic["id"], html_url, topic["tags"]])

248
docs/index.html Normal file
View file

@ -0,0 +1,248 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="Dashboard" />
<title>Baza Zasobów Hackerspace Trójmiasto</title>
<link rel="shortcut icon" href="static/favicon.ico" />
<!-- Font Awesome CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"/>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity=""/>
<link rel="stylesheet" href="static/css/style.css" />
<!-- DataTables CSS -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css"
/>
</head>
<body>
<div id="site-body" class="container-fluid">
<div class="row flex-nonwrap">
<div class="sidenav"></div>
<div class="main">
<h1>Baza Zasobów Hackerspace Trójmiasto</h1>
<table id="dashboardTable">
<thead>
<tr>
<td>id</td>
<td>title</td>
<td>tags</td>
</tr>
</thead>
<tbody>
<tr>
<td>45</td>
<td><a href="https://kb.hs3.pl/t/45">Jak stworzyć nowy wpis do bazy zasobów Hackerspace Trójmiasto?</a></td>
<td>[]</td>
</tr>
<tr>
<td>20</td>
<td><a href="https://kb.hs3.pl/t/20">O kategorii: Baza Wiedzy Hackerspace'u</a></td>
<td>[]</td>
</tr>
<tr>
<td>108</td>
<td><a href="https://kb.hs3.pl/t/108">PC Engines APU2 Router Box</a></td>
<td>['cow-work', 'networking']</td>
</tr>
<tr>
<td>61</td>
<td><a href="https://kb.hs3.pl/t/61">HS3 BOFH</a></td>
<td>['cow-work', 'garage', 'events', 'bofh']</td>
</tr>
<tr>
<td>93</td>
<td><a href="https://kb.hs3.pl/t/93">King Bob</a></td>
<td>['cow-work']</td>
</tr>
<tr>
<td>92</td>
<td><a href="https://kb.hs3.pl/t/92">Drukarka 3D Creality K1 Max</a></td>
<td>['tools', 'workshop', '3d-print']</td>
</tr>
<tr>
<td>91</td>
<td><a href="https://kb.hs3.pl/t/91">Drukarka 3D Creality Ender 3</a></td>
<td>['tools', 'workshop', '3d-print']</td>
</tr>
<tr>
<td>90</td>
<td><a href="https://kb.hs3.pl/t/90">Chciejlista</a></td>
<td>[]</td>
</tr>
<tr>
<td>85</td>
<td><a href="https://kb.hs3.pl/t/85">Komu powinien służyć Spejs</a></td>
<td>[]</td>
</tr>
<tr>
<td>84</td>
<td><a href="https://kb.hs3.pl/t/84">Budżet</a></td>
<td>[]</td>
</tr>
<tr>
<td>83</td>
<td><a href="https://kb.hs3.pl/t/83">Hackerspace Dragon Dreaming</a></td>
<td>[]</td>
</tr>
<tr>
<td>82</td>
<td><a href="https://kb.hs3.pl/t/82">Biblioteka</a></td>
<td>['cow-work', 'books']</td>
</tr>
<tr>
<td>66</td>
<td><a href="https://kb.hs3.pl/t/66">Apteczki</a></td>
<td>['cow-work', 'garage', 'bhp']</td>
</tr>
<tr>
<td>44</td>
<td><a href="https://kb.hs3.pl/t/44">Brayton Power</a></td>
<td>['garage', 'projects']</td>
</tr>
<tr>
<td>52</td>
<td><a href="https://kb.hs3.pl/t/52">Evil Submarine</a></td>
<td>['cow-work', 'projects']</td>
</tr>
<tr>
<td>50</td>
<td><a href="https://kb.hs3.pl/t/50">Infinity mirror (duże)</a></td>
<td>['garage', 'projects']</td>
</tr>
<tr>
<td>47</td>
<td><a href="https://kb.hs3.pl/t/47">Cricut Maker 3 ploter tnący</a></td>
<td>['tools', 'workshop']</td>
</tr>
<tr>
<td>41</td>
<td><a href="https://kb.hs3.pl/t/41">Wiertarka PSB 500 RE BOSCH</a></td>
<td>['garage', 'tools']</td>
</tr>
<tr>
<td>46</td>
<td><a href="https://kb.hs3.pl/t/46">What the Duck</a></td>
<td>['cow-work', 'wled']</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
<footer>
Created by <a href="https://github.com/MartaSien">Marta Sienkiewicz</a>
</footer>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<!-- DataTables JS -->
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#dashboardTable').DataTable({paging: false});
});
</script>
</body>
</html>

14
docs/static/css/style.css vendored Normal file
View file

@ -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;
}

34
main.py
View file

@ -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!")

View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="description" content="Dashboard" />
<title>Baza Zasobów Hackerspace Trójmiasto</title>
<link rel="shortcut icon" href="static/favicon.ico" />
<!-- Font Awesome CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"/>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity=""/>
<link rel="stylesheet" href="static/css/style.css" />
<!-- DataTables CSS -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.6/css/jquery.dataTables.min.css"
/>
</head>
<body>
{% block body %}{% endblock body %}
</body>
<footer>
Created by <a href="https://github.com/MartaSien">Marta Sienkiewicz</a>
</footer>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<!-- DataTables JS -->
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#dashboardTable').DataTable({paging: false});
});
</script>
</body>
</html>

View file

@ -0,0 +1,28 @@
{% extends "_base_template.html" %} {% block body %}
<div id="site-body" class="container-fluid">
<div class="row flex-nonwrap">
<div class="sidenav">{% block sidenav %}{% endblock sidenav %}</div>
<div class="main">
<h1>Baza Zasobów Hackerspace Trójmiasto</h1>
<table id="dashboardTable">
<thead>
<tr>
{% for cell in t_header %}
<td>{{cell}}</td>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in t_body %}
<tr>
{% for cell in row %}
<td>{{cell}}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock body %}

View file

@ -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;
}

View file

@ -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,"<a href=""https://kb.hs3.pl/t/45"">Jak stworzyć nowy wpis do bazy zasobów Hackerspace Trójmiasto?</a>",[]
20,"<a href=""https://kb.hs3.pl/t/20"">O kategorii: Baza Wiedzy Hackerspace'u</a>",[]
108,"<a href=""https://kb.hs3.pl/t/108"">PC Engines APU2 Router Box</a>","['cow-work', 'networking']"
61,"<a href=""https://kb.hs3.pl/t/61"">HS3 BOFH</a>","['cow-work', 'garage', 'events', 'bofh']"
93,"<a href=""https://kb.hs3.pl/t/93"">King Bob</a>",['cow-work']
92,"<a href=""https://kb.hs3.pl/t/92"">Drukarka 3D Creality K1 Max</a>","['tools', 'workshop', '3d-print']"
91,"<a href=""https://kb.hs3.pl/t/91"">Drukarka 3D Creality Ender 3</a>","['tools', 'workshop', '3d-print']"
90,"<a href=""https://kb.hs3.pl/t/90"">Chciejlista</a>",[]
85,"<a href=""https://kb.hs3.pl/t/85"">Komu powinien służyć Spejs</a>",[]
84,"<a href=""https://kb.hs3.pl/t/84"">Budżet</a>",[]
83,"<a href=""https://kb.hs3.pl/t/83"">Hackerspace Dragon Dreaming</a>",[]
82,"<a href=""https://kb.hs3.pl/t/82"">Biblioteka</a>","['cow-work', 'books']"
66,"<a href=""https://kb.hs3.pl/t/66"">Apteczki</a>","['cow-work', 'garage', 'bhp']"
44,"<a href=""https://kb.hs3.pl/t/44"">Brayton Power</a>","['garage', 'projects']"
52,"<a href=""https://kb.hs3.pl/t/52"">Evil Submarine</a>","['cow-work', 'projects']"
50,"<a href=""https://kb.hs3.pl/t/50"">Infinity mirror (duże)</a>","['garage', 'projects']"
47,"<a href=""https://kb.hs3.pl/t/47"">Cricut Maker 3 ploter tnący</a>","['tools', 'workshop']"
41,"<a href=""https://kb.hs3.pl/t/41"">Wiertarka PSB 500 RE BOSCH</a>","['garage', 'tools']"
46,"<a href=""https://kb.hs3.pl/t/46"">What the Duck</a>","['cow-work', 'wled']"

Can't render this file because it contains an unexpected character in line 4 and column 101.