show user's points on dashboard

This commit is contained in:
Lili (Tlapka) 2022-10-18 14:04:15 +02:00
parent ecb794b8fa
commit c12bcd68c2
3 changed files with 35 additions and 2 deletions

View File

@ -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(

View File

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

View File

@ -5,6 +5,20 @@
<title>Redeems Dashboard</title>
</head>
<body>
{% if (username and user_points ) %}
<table>
<thead>
<tr>
<th>Your points balance:</th>
</tr>
</thead>
<tbody>
<td> {{ username }} </td>
<td> {{ user_points }} </td>
</tbody>
</table>
{% endif %}
{% if counters %}
<table>
<thead>