From 3c5a09b2dea14427017206396267dd62fa379513 Mon Sep 17 00:00:00 2001 From: Lili Date: Wed, 12 Oct 2022 15:48:57 +0200 Subject: [PATCH] update dashboard + dashboard helpers also untested --- tlapbot/owncast_helpers.py | 9 +++++++++ tlapbot/owncast_redeem_dashboard.py | 11 ++++------- tlapbot/templates/dashboard.html | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tlapbot/owncast_helpers.py b/tlapbot/owncast_helpers.py index 236dcda..2f32438 100644 --- a/tlapbot/owncast_helpers.py +++ b/tlapbot/owncast_helpers.py @@ -141,6 +141,15 @@ def clear_redeem_queue(db): except Error as e: print("Error occured deleting redeem queue:", e.args[0]) +def all_counters(db): + try: + cursor = db.execute( + """SELECT counters.name, counters.count FROM counters""" + ) + return cursor.fetchall() + except Error as e: + print("Error occured selecting all counters:", e.args[0]) + def pretty_redeem_queue(db): try: cursor = db.execute( diff --git a/tlapbot/owncast_redeem_dashboard.py b/tlapbot/owncast_redeem_dashboard.py index 27c7c64..e0fd390 100644 --- a/tlapbot/owncast_redeem_dashboard.py +++ b/tlapbot/owncast_redeem_dashboard.py @@ -7,14 +7,11 @@ bp = Blueprint('redeem_dashboard', __name__) @bp.route('/dashboard',methods=['GET']) def dashboard(): - queue = pretty_redeem_queue(get_db()) - number_of_drinks = 0 + db = get_db() + queue = pretty_redeem_queue(db) + counters = all_counters(db) utc_timezone = timezone.utc - if queue is not None: - for row in queue: - if row[1] == "drink": - number_of_drinks += 1 return render_template('dashboard.html', queue=queue, - number_of_drinks=number_of_drinks, + counters=counters, utc_timezone=utc_timezone) \ No newline at end of file diff --git a/tlapbot/templates/dashboard.html b/tlapbot/templates/dashboard.html index f4865e2..5469bd2 100644 --- a/tlapbot/templates/dashboard.html +++ b/tlapbot/templates/dashboard.html @@ -5,12 +5,21 @@ Redeems Dashboard + {% if counters %} + + + + + - - + {% for counter in counters %} + +
Counters
Number of drinks: {{ number_of_drinks }} {{ counter[0] }} {{ counter[1] }}
+ {% endif %} + {% if queue %} @@ -18,6 +27,7 @@ + {% for row in queue %} @@ -25,6 +35,7 @@ + {% endfor %}
time redeem redeemernote
{{ row[0].replace(tzinfo=utc_timezone).astimezone().strftime("%H:%M") }} {{ row[1] }} {{ row[2] }}{{ row[3] }}