From 89bffd2ee328a19ee4839cd4c25cb98b2c313cbc Mon Sep 17 00:00:00 2001 From: miklo Date: Sun, 23 Nov 2025 19:55:00 +0100 Subject: [PATCH] initial --- .gitignore | 31 ++++++++++++++++ app.py | 85 ++++++++++++++++++++++++++++++++++++++++++++ templates/admin.html | 55 ++++++++++++++++++++++++++++ templates/index.html | 24 +++++++++++++ 4 files changed, 195 insertions(+) create mode 100644 .gitignore create mode 100644 app.py create mode 100644 templates/admin.html create mode 100644 templates/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c0fe227 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Python +__pycache__/ +*.py[cod] +*.pyo +*.pyd +env/ +venv/ +.env + +# SQLite DB +*.db +queue.db + +# Flask debug / instance +instance/ + +# Byte-compiled / cache +*.egg-info/ +.eggs/ + +# IDEs +.vscode/ +.idea/ + +# System +.DS_Store +Thumbs.db + +# Do not track Pipfile and Pipfile.lock +Pipfile +Pipfile.lock diff --git a/app.py b/app.py new file mode 100644 index 0000000..b5b7838 --- /dev/null +++ b/app.py @@ -0,0 +1,85 @@ +from flask import Flask, render_template, request, redirect, url_for, g, jsonify +import sqlite3 +import os + +DB = "queue.db" +app = Flask(__name__) + +def get_db(): + db = getattr(g, "_db", None) + if db is None: + need_init = not os.path.exists(DB) + db = g._db = sqlite3.connect(DB, check_same_thread=False) + db.row_factory = sqlite3.Row + if need_init: + init_db(db) + return db + +def init_db(db): + cur = db.cursor() + cur.execute("""CREATE TABLE items ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + number TEXT, + status TEXT -- 'waiting', 'called', 'done' + )""") + db.commit() + +@app.teardown_appcontext +def close_db(exc): + db = getattr(g, "_db", None) + if db: + db.close() + +# Main display for clients +@app.route("/") +def index(): + db = get_db() + cur = db.execute("SELECT number FROM items WHERE status='called' ORDER BY id DESC LIMIT 1") + row = cur.fetchone() + current = row["number"] if row else "" + return render_template("index.html", current=current) + +# API endpoint used by clients to poll current number (JSON) +@app.route("/current") +def current_api(): + db = get_db() + cur = db.execute("SELECT number FROM items WHERE status='called' ORDER BY id DESC LIMIT 1") + row = cur.fetchone() + return jsonify(current=(row["number"] if row else "")) + +# Admin UI: start/reset system by providing count of tickets (1..N) +@app.route("/admin", methods=["GET", "POST"]) +def admin(): + db = get_db() + if request.method == "POST": + action = request.form.get("action") + if action == "start": + n = int(request.form.get("count", "0")) + db.execute("DELETE FROM items") + for i in range(1, n+1): + db.execute("INSERT INTO items (number, status) VALUES (?, 'waiting')", (str(i),)) + db.commit() + elif action == "call": + num = request.form.get("num") + # mark chosen number as called + db.execute("UPDATE items SET status='called' WHERE number=? AND status='waiting'", (num,)) + db.commit() + elif action == "done": + num = request.form.get("num") + db.execute("UPDATE items SET status='done' WHERE number=? AND status='called'", (num,)) + db.commit() + elif action == "reset": + db.execute("DELETE FROM items") + db.commit() + return redirect(url_for("admin")) + + cur_wait = db.execute("SELECT number FROM items WHERE status='waiting' ORDER BY id").fetchall() + cur_called = db.execute("SELECT number FROM items WHERE status='called' ORDER BY id").fetchall() + cur_done = db.execute("SELECT number FROM items WHERE status='done' ORDER BY id").fetchall() + return render_template("admin.html", + waiting=[r["number"] for r in cur_wait], + called=[r["number"] for r in cur_called], + done=[r["number"] for r in cur_done]) + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=5000, debug=True) diff --git a/templates/admin.html b/templates/admin.html new file mode 100644 index 0000000..b6fdde8 --- /dev/null +++ b/templates/admin.html @@ -0,0 +1,55 @@ + + + + + Panel admina — kolejka + + + +

Panel admina

+ +
+ + + +
+ +
+
+

Oczekujące

+ {% for n in waiting %} +
+ + +
+ {% else %} +

brak

+ {% endfor %} +
+ +
+

Wywołane (obecne)

+ {% for n in called %} +
+ {{n}} + + +
+ {% else %} +

brak

+ {% endfor %} +
+ +
+

Obsłużone

+ {% for n in done %} +
{{n}}
+ {% else %} +

brak

+ {% endfor %} +
+
+ + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..5333f6e --- /dev/null +++ b/templates/index.html @@ -0,0 +1,24 @@ + + + + + Wywoływany numer + + + + +

Proszę podejść do okienka

+
-
+ +