From c12bcd68c245e00fa9facd1c2fce987959581fd2 Mon Sep 17 00:00:00 2001 From: Lili Date: Tue, 18 Oct 2022 14:04:15 +0200 Subject: [PATCH] show user's points on dashboard --- tlapbot/owncast_helpers.py | 11 +++++++++++ tlapbot/owncast_redeem_dashboard.py | 12 ++++++++++-- tlapbot/templates/dashboard.html | 14 ++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/tlapbot/owncast_helpers.py b/tlapbot/owncast_helpers.py index 44898df..d432555 100644 --- a/tlapbot/owncast_helpers.py +++ b/tlapbot/owncast_helpers.py @@ -45,6 +45,17 @@ def read_users_points(db, user_id): print("To user:", user_id) +def read_users_points_from_username(db, username): + try: + cursor = db.execute( + "SELECT points FROM points WHERE name = ?", + (username,) + ) + return cursor.fetchone()[0] + except Error as e: + print("Error occured reading points from username:", e.args[0]) + print("To user:", username) + def give_points_to_user(db, user_id, points): try: db.execute( diff --git a/tlapbot/owncast_redeem_dashboard.py b/tlapbot/owncast_redeem_dashboard.py index 4203cff..db71a79 100644 --- a/tlapbot/owncast_redeem_dashboard.py +++ b/tlapbot/owncast_redeem_dashboard.py @@ -1,6 +1,7 @@ -from flask import render_template, Blueprint +from flask import render_template, Blueprint, request from tlapbot.db import get_db -from tlapbot.owncast_helpers import pretty_redeem_queue, all_counters +from tlapbot.owncast_helpers import (pretty_redeem_queue, all_counters, + read_users_points_from_username) from datetime import datetime, timezone bp = Blueprint('redeem_dashboard', __name__) @@ -11,8 +12,15 @@ def dashboard(): db = get_db() queue = pretty_redeem_queue(db) counters = all_counters(db) + username = request.args.get("username") + if username is not None: + user_points = read_users_points_from_username(db, username) + else: + user_points = None utc_timezone = timezone.utc return render_template('dashboard.html', queue=queue, counters=counters, + username=username, + user_points=user_points, utc_timezone=utc_timezone) diff --git a/tlapbot/templates/dashboard.html b/tlapbot/templates/dashboard.html index 7b13cf2..b6814b1 100644 --- a/tlapbot/templates/dashboard.html +++ b/tlapbot/templates/dashboard.html @@ -5,6 +5,20 @@ Redeems Dashboard + {% if (username and user_points ) %} + + + + + + + + + + +
Your points balance:
{{ username }} {{ user_points }}
+ {% endif %} + {% if counters %}