beginning work on redeem dashboard

for now it's just a static site
This commit is contained in:
Lili (Tlapka) 2022-09-07 16:44:59 +02:00
parent 0bca3d65a8
commit 20c2d2536e
5 changed files with 78 additions and 5 deletions

View File

@ -17,7 +17,9 @@ def create_app(test_config=None):
from . import db from . import db
from . import owncast_webhooks from . import owncast_webhooks
from . import owncast_redeem_dashboard
app.register_blueprint(owncast_webhooks.bp) app.register_blueprint(owncast_webhooks.bp)
app.register_blueprint(owncast_redeem_dashboard.bp)
db.init_app(app) db.init_app(app)
def proxy_job(): def proxy_job():

View File

@ -31,9 +31,11 @@ def use_points(db, user_id, points):
(points, user_id,) (points, user_id,)
) )
db.commit() db.commit()
return True
except Error as e: except Error as e:
print("Error occured using points:", e.args[0]) print("Error occured using points:", e.args[0])
print("From user:", user_id, " amount of points:", points) print("From user:", user_id, " amount of points:", points)
return False
def give_points_to_chat(db): def give_points_to_chat(db):
url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/clients' url = current_app.config['OWNCAST_INSTANCE_URL'] + '/api/integrations/clients'
@ -90,3 +92,23 @@ def send_chat(message):
headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']} headers = {"Authorization": "Bearer " + current_app.config['OWNCAST_ACCESS_TOKEN']}
r = requests.post(url, headers=headers, json={"body": message}) r = requests.post(url, headers=headers, json={"body": message})
return r.json() return r.json()
def add_to_redeem_queue(db, user_id, redeem_name):
try:
cursor = db.execute(
"INSERT INTO redeem_queue(redeem, redeemer_id) VALUES(?, ?)",
(redeem_name, user_id)
)
db.commit()
except Error as e:
print("Error occured adding to redeem queue:", e.args[0])
print("To user:", user_id, " with redeem:", redeem_name)
def whole_redeem_queue(db):
try:
cursor = db.execute(
"SELECT * from redeem_queue"
)
return cursor.fetchall()
except Error as e:
print("Error occured printing redeem queue:", e.args[0])

View File

@ -0,0 +1,14 @@
from flask import render_template, Blueprint
from tlapbot.db import get_db
from tlapbot.owncast_helpers import whole_redeem_queue
bp = Blueprint('redeem_dashboard', __name__)
@bp.route('/dashboard',methods=['GET'])
def dashboard():
queue = whole_redeem_queue(get_db())
number_of_drinks = 0
for row in queue:
if row[2] == "drink":
number_of_drinks += 1
return render_template('dashboard.html', queue=queue, number_of_drinks=number_of_drinks)

View File

@ -36,10 +36,14 @@ def owncast_webhook():
send_chat(message) send_chat(message)
elif "!drink" in data["eventData"]["body"]: elif "!drink" in data["eventData"]["body"]:
points = read_users_points(db, user_id) points = read_users_points(db, user_id)
if points is not None: if points is not None and points > 60:
if points > 60: if use_points(db, user_id, 60):
use_points(db, user_id, 60) add_to_redeem_queue(db, user_id, "drink")
send_chat("Enjoy your DRINK........... sips") elif "!queue" in data["eventData"]["body"]:
queue = whole_redeem_queue(db)
print("ID | timestamp | redeem | redeemer_id ")
for row in queue:
print(row[0], " ", row[1], " ", row[2], " ", row[3])
# else: # DEBUG: give points for message # else: # DEBUG: give points for message
# give_points_to_chat(db) # give_points_to_chat(db)
return data return data

View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Redeems Dashboard</title>
</head>
<body>
<table>
<tbody>
<td> Number of drinks: </td>
<td> {{ number_of_drinks }} </td>
</tbody>
</table>
<table>
<thead>
<tr>
<th>time</th>
<th>redeem</th>
<th>redeemer</th>
</tr>
</thead>
{% for row in queue %}
<tbody>
<td>{{ row[1] }}</td>
<td>{{ row[2] }}</td>
<td>{{ row[3] }}</td>
</tbody>
{% endfor %}
</table>
</body>
</html>