diff --git a/chanbans/http.py b/chanbans/http.py index 5c674a6..a15a1d6 100644 --- a/chanbans/http.py +++ b/chanbans/http.py @@ -13,6 +13,7 @@ from .db import get_db, search_db # 2023-07-24 - eating stirfry tonight. It's pretty bad. # 2023-07-31 - In a meeting. Hope I don't get caught +# 2023-09-09 - watching slime's stream def route_url(url: str, args: Optional[Mapping[str, Any]] = None): @@ -34,6 +35,12 @@ def static_url(resource: str): return f"{config.STATIC_ROOT}/{resource}" +def stats_table_data(): + with get_db() as db: + curs = db.execute("SELECT board, count(*) as bans FROM bans GROUP BY board") + return sorted(list(curs.fetchall()), key=lambda row: -row["bans"]) + + _env = Environment( loader=PackageLoader("chanbans"), autoescape=select_autoescape(), @@ -42,6 +49,7 @@ _env.globals.update( { "route_url": route_url, "static_url": static_url, + "stats_table_data": stats_table_data, } ) @@ -183,6 +191,7 @@ app.add_routes( web.get(config.HTTP_ROOT, IndexView), web.get(f"{config.HTTP_ROOT}/faq", template_view_factory("faq.html")), web.get(f"{config.HTTP_ROOT}/news", template_view_factory("news.html")), + web.get(f"{config.HTTP_ROOT}/stats", template_view_factory("stats.html")), ] ) diff --git a/chanbans/templates/stats.html b/chanbans/templates/stats.html new file mode 100644 index 0000000..2edb115 --- /dev/null +++ b/chanbans/templates/stats.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% block title %}Stats{% endblock title %} + +{% block main %} +
+
+
+ Click here to see the full histogram view +
++
| Board | +Bans | +
|---|---|
| {{row['board']}} | +{{row["bans"]}} | +