From: Max Value Date: Sat, 12 Apr 2025 18:18:06 +0000 (+0100) Subject: Added real-time buying and chart to display data X-Git-Url: https://git.ozva.co.uk/?a=commitdiff_plain;h=d413966b49630a40e92eb45c25acc35fe913945b;p=shopping-channel Added real-time buying and chart to display data Added svgs for the pricing display --- diff --git a/extensions/pricing.html b/extensions/pricing.html index cbb5f35..d7b25a3 100644 --- a/extensions/pricing.html +++ b/extensions/pricing.html @@ -13,6 +13,7 @@ body { background-color: white; font-family: "Archivo", sans-serif; + font-size: 0.8em; color: black; } #main > *:not(hr) { @@ -30,6 +31,7 @@ body { #subtext { color: white; font-family: "Pacifico", cursive; + line-height: 1.3em; background-color: violet; } hr { @@ -37,6 +39,26 @@ hr { padding: 0; border-color: var(--dark); } +img { + position: fixed; + width: 100vw; + left: 0; + top: calc(95vh - 2em); + +} +#buy { + position: fixed; + width: 100vw; + height: 2em; + bottom: 0; + left: 0; + text-align: center; + font-size: 1em; + font-weight: bold; + line-height: 2em; + border: none; + background-color: transparent; +} .white { color: rgba(255,255,255,1); @@ -68,7 +90,14 @@ hr {

Now Only:

-
+
+
+ + + + + + diff --git a/extensions/pricing.js b/extensions/pricing.js index 1f17b46..72510ab 100644 --- a/extensions/pricing.js +++ b/extensions/pricing.js @@ -60,3 +60,7 @@ function update() { } setInterval(update, 5000); + +function buy() { + fetch("http://127.0.0.1:8000/api/buy") +} diff --git a/schema b/schema deleted file mode 100644 index a2a35af..0000000 --- a/schema +++ /dev/null @@ -1,82 +0,0 @@ -CREATE TABLE state ( - id INTEGER PRIMARY KEY, - item_id INTEGER, - discount INTEGER, - discount_1 INTEGER, - discount_2 INTEGER, - discount_3 INTEGER, - discount_4 INTEGER, - discount_change INTEGER, - percent_remaining INTEGER, - crawler_top_index INTEGER, - list_crawler_bottom TEXT, - banner_index INTEGER, - bool_rounding INTEGER, - bool_all INTEGER, - bool_product INTEGER, - bool_extra INTEGER, - bool_banner INTEGER, - bool_sigil INTEGER, - bool_number INTEGER, - end_timer_1 INTEGER, - end_timer_2 INTEGER, - end_timer_3 INTEGER, - end_timer_4 INTEGER, - end_timer_5 INTEGER, - end_timer_6 INTEGER, - end_timer_main INTEGER, - end_timer_shout INTEGER, - focus_timer_1 INTEGER, - focus_timer_2 INTEGER, - focus_timer_3 INTEGER, - focus_timer_4 INTEGER, - focus_timer_5 INTEGER, - focus_timer_6 INTEGER, - timer_offset INTEGER, - current_position INTEGER, - movement_speed INTEGER, - movement_function TEXT, - shout TEXT, - note TEXT -); - -INSERT INTO state ( - id, - item_id, - discount, - discount_1, - discount_2, - discount_3, - discount_4, - discount_change, - percent_remaining, - crawler_top_index, - list_crawler_bottom, - banner_index, - bool_rounding, - bool_all, - bool_product, - bool_extra, - bool_banner, - bool_sigil, - bool_number, - end_timer_1, - end_timer_2, - end_timer_3, - end_timer_4, - end_timer_5, - end_timer_6, - end_timer_main, - end_timer_shout, - focus_timer_1, - focus_timer_2, - focus_timer_3, - focus_timer_4, - focus_timer_5, - focus_timer_6, - timer_offset, - current_position, - movement_speed, - movement_function, - shout, - note) VALUES (1, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 50, 100, 0, '[0,1]', 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 40, 'linear', 'test shout', 'test note'); diff --git a/schema1 b/schema1 new file mode 100644 index 0000000..a2a35af --- /dev/null +++ b/schema1 @@ -0,0 +1,82 @@ +CREATE TABLE state ( + id INTEGER PRIMARY KEY, + item_id INTEGER, + discount INTEGER, + discount_1 INTEGER, + discount_2 INTEGER, + discount_3 INTEGER, + discount_4 INTEGER, + discount_change INTEGER, + percent_remaining INTEGER, + crawler_top_index INTEGER, + list_crawler_bottom TEXT, + banner_index INTEGER, + bool_rounding INTEGER, + bool_all INTEGER, + bool_product INTEGER, + bool_extra INTEGER, + bool_banner INTEGER, + bool_sigil INTEGER, + bool_number INTEGER, + end_timer_1 INTEGER, + end_timer_2 INTEGER, + end_timer_3 INTEGER, + end_timer_4 INTEGER, + end_timer_5 INTEGER, + end_timer_6 INTEGER, + end_timer_main INTEGER, + end_timer_shout INTEGER, + focus_timer_1 INTEGER, + focus_timer_2 INTEGER, + focus_timer_3 INTEGER, + focus_timer_4 INTEGER, + focus_timer_5 INTEGER, + focus_timer_6 INTEGER, + timer_offset INTEGER, + current_position INTEGER, + movement_speed INTEGER, + movement_function TEXT, + shout TEXT, + note TEXT +); + +INSERT INTO state ( + id, + item_id, + discount, + discount_1, + discount_2, + discount_3, + discount_4, + discount_change, + percent_remaining, + crawler_top_index, + list_crawler_bottom, + banner_index, + bool_rounding, + bool_all, + bool_product, + bool_extra, + bool_banner, + bool_sigil, + bool_number, + end_timer_1, + end_timer_2, + end_timer_3, + end_timer_4, + end_timer_5, + end_timer_6, + end_timer_main, + end_timer_shout, + focus_timer_1, + focus_timer_2, + focus_timer_3, + focus_timer_4, + focus_timer_5, + focus_timer_6, + timer_offset, + current_position, + movement_speed, + movement_function, + shout, + note) VALUES (1, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 50, 100, 0, '[0,1]', 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 0, 0, 40, 'linear', 'test shout', 'test note'); diff --git a/schema2 b/schema2 new file mode 100644 index 0000000..27d2f6a --- /dev/null +++ b/schema2 @@ -0,0 +1,4 @@ +CREATE TABLE orders ( + id INTEGER PRIMARY KEY, + timestamp INTEGER +); diff --git a/static/assets/sigil1.svg b/static/assets/sigil1.svg new file mode 100644 index 0000000..c33ca7c --- /dev/null +++ b/static/assets/sigil1.svg @@ -0,0 +1,688 @@ + + + + +Created by potrace 1.16, written by Peter Selinger 2001-2019 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/assets/sigil2.svg b/static/assets/sigil2.svg new file mode 100644 index 0000000..31fb20e --- /dev/null +++ b/static/assets/sigil2.svg @@ -0,0 +1,951 @@ + + + + +Created by potrace 1.16, written by Peter Selinger 2001-2019 + + + + + + + + + + + + + + + + + + + + + diff --git a/static/assets/sigil3.svg b/static/assets/sigil3.svg new file mode 100644 index 0000000..3f2816d --- /dev/null +++ b/static/assets/sigil3.svg @@ -0,0 +1,713 @@ + + + + +Created by potrace 1.16, written by Peter Selinger 2001-2019 + + + + + + + + + + + + + + + + + + + + + diff --git a/static/assets/sigil4.svg b/static/assets/sigil4.svg new file mode 100644 index 0000000..1a42052 --- /dev/null +++ b/static/assets/sigil4.svg @@ -0,0 +1,1203 @@ + + + + +Created by potrace 1.16, written by Peter Selinger 2001-2019 + + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/assets/sigil5.svg b/static/assets/sigil5.svg new file mode 100644 index 0000000..97092e8 --- /dev/null +++ b/static/assets/sigil5.svg @@ -0,0 +1,898 @@ + + + + +Created by potrace 1.16, written by Peter Selinger 2001-2019 + + + + + + + + + + + + + + + diff --git a/teleshopping.py b/teleshopping.py index 84da8f7..e78d1cb 100755 --- a/teleshopping.py +++ b/teleshopping.py @@ -12,6 +12,7 @@ from ast import literal_eval from flask_cors import CORS import sqlite3 import json +import time INCREMENT = 18 @@ -79,6 +80,10 @@ def display_page(): def sounds_page(): return Response(render_template("sounds.html"), mimetype="text/html") +@app.route("/chart") +def chart_page(): + return Response(render_template("chart.html"), mimetype="text/html") + @@ -170,6 +175,7 @@ def admin_page(page): if page == "price": return Response(render_template("price.html", data=api(), items=static_data['items']), mimetype="text/html") + else: return "", 404 @@ -262,6 +268,55 @@ def generate_docs(): +@app.route("/api/buy") +def buy(): + with sqlite3.connect(path.join(app.root_path, "data.db")) as connection: + cursor = connection.cursor() + cursor.execute(f""" + INSERT INTO orders VALUES + (NULL, {round(time.time())}) + """) + connection.commit() + + return "", 200 + +@app.route("/api/buy/data") +@auth.login_required +def buy_data(): + data = [] + with sqlite3.connect(path.join(app.root_path, "data.db")) as connection: + cursor = connection.cursor() + + current = round(time.time() / 5) * 5 + + for start in range(current - 600, current, 5): + result = cursor.execute(f""" + SELECT COUNT(*) + FROM orders + WHERE timestamp BETWEEN {start - 1} and {start + 5}; + """) + result = result.fetchone()[0] + data.append(result) + + return jsonify(data) + +@app.route("/api/buy/clear") +@auth.login_required +def buy_clear(): + with open(path.join(app.root_path, "schema2"), "r", encoding="utf-8") as f: + schema = f.read() + + with sqlite3.connect(path.join(app.root_path, "data.db")) as connection: + cursor = connection.cursor() + cursor.execute("DROP TABLE orders;") + cursor.execute(schema) + connection.commit() + + return "", 200 + + + + # if this is the first incoming request do a sanity check on the db # this might happen a few times because of threading, but it doesnt slow requests that much first_request = True @@ -269,7 +324,7 @@ first_request = True def check_database(): global first_request if first_request: - with open(path.join(app.root_path, "schema"), "r", encoding="utf-8") as f: + with open(path.join(app.root_path, "schema1"), "r", encoding="utf-8") as f: schema, load = f.read().split("\n\n") with sqlite3.connect(path.join(app.root_path, "data.db")) as connection: @@ -284,7 +339,16 @@ def check_database(): try: cursor.execute("DROP TABLE state;") # catch if there is no table "state" except: pass cursor.execute(schema) - cursor.execute(load) + connection.commit() + + with open(path.join(app.root_path, "schema2"), "r", encoding="utf-8") as f: + schema = f.read() + + with sqlite3.connect(path.join(app.root_path, "data.db")) as connection: + cursor = connection.cursor() + try: cursor.execute("DROP TABLE orders;") + except: pass + cursor.execute(schema) connection.commit() # generate_docs() # This might be a bad idea diff --git a/templates/admin.html b/templates/admin.html index bb9cc3f..0eb6c93 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -30,6 +30,7 @@ diff --git a/templates/chart.html b/templates/chart.html new file mode 100644 index 0000000..13e6190 --- /dev/null +++ b/templates/chart.html @@ -0,0 +1,56 @@ + + + + + XMDV Admin - Sales + + + + + + +

Total sales in last 10 minutes: 0

+ + +