From d413966b49630a40e92eb45c25acc35fe913945b Mon Sep 17 00:00:00 2001 From: Max Value Date: Sat, 12 Apr 2025 19:18:06 +0100 Subject: [PATCH] Added real-time buying and chart to display data Added svgs for the pricing display --- extensions/pricing.html | 31 +- extensions/pricing.js | 4 + schema => schema1 | 0 schema2 | 4 + static/assets/sigil1.svg | 688 ++++++++++++++++++++++ static/assets/sigil2.svg | 951 ++++++++++++++++++++++++++++++ static/assets/sigil3.svg | 713 ++++++++++++++++++++++ static/assets/sigil4.svg | 1203 ++++++++++++++++++++++++++++++++++++++ static/assets/sigil5.svg | 898 ++++++++++++++++++++++++++++ teleshopping.py | 68 ++- templates/admin.html | 1 + templates/chart.html | 56 ++ 12 files changed, 4614 insertions(+), 3 deletions(-) rename schema => schema1 (100%) create mode 100644 schema2 create mode 100644 static/assets/sigil1.svg create mode 100644 static/assets/sigil2.svg create mode 100644 static/assets/sigil3.svg create mode 100644 static/assets/sigil4.svg create mode 100644 static/assets/sigil5.svg create mode 100644 templates/chart.html 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/schema1 similarity index 100% rename from schema rename to schema1 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

+ + + -- 2.39.2