From c03f2c4d645a1b36e4038cec933ded31546729af Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Tue, 6 Oct 2026 08:34:47 +1300 Subject: print queue --- backend.py | 19 +++++++++++++++++++ main.py | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/backend.py b/backend.py index 39334b8..811db4f 100644 --- a/backend.py +++ b/backend.py @@ -1,7 +1,10 @@ from flask import Flask +from pathlib import Path +import threading import os app = Flask(__name__) +print_lock = threading.Lock() @app.get("/automate/hack_this_club") def hack_this_club(): @@ -13,5 +16,21 @@ def hack_this_club(): os.system('lp -d Canon_G3060 /opsec.txt') return "ok" +@app.get("/automate/print_queue") +def print_queue(): + if not print_lock.acquire(blocking=False): + print("print queue is already running") + return "print queue busy", 400 + print("printing file(s) in /srv/shares/public/printing") + path = Path("/srv/shares/public/printing") + files = [f for f in path.iterdir() if f.is_file()] + + for file in files: + subprocess.run(["lp", "-d", "Canon_G3060", str(file)], check=True) + subprocess.run(["mv", str(file), "/srv/shares/public/printed"], check=True) + + print(f"printed {len(files)} file(s)") + return f"printed {len(files)} file(s)" + if __name__ == "__main__": app.run(host="0.0.0.0", port=6732) diff --git a/main.py b/main.py index 960ac97..0a201b9 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from evdev import InputDevice, list_devices, ecodes from urllib.request import urlopen from urllib.error import HTTPError, URLError -SCANCODES = {0x11A: "up", 0x148: "down", 0x147: "left", 0x107: "right", 0x106: "ok", 0x141: "play/pause", 0x11c: "power", 0x103: "vol+", 0x142: "vol-", 0x101: "app"} +SCANCODES = {0x11A: "up", 0x148: "down", 0x147: "left", 0x107: "right", 0x106: "ok", 0x141: "play/pause", 0x11c: "power", 0x103: "vol+", 0x142: "vol-", 0x101: "app", 0x154: "1"} device = None last = 0x00 @@ -27,6 +27,8 @@ def do_action(action: str): homelab_request("hack_this_club") # /j (test endpoint) elif action == "play/pause": homelab_request("music") + elif action == "1": + homelab_request("print_queue") for path in list_devices(): candidate = InputDevice(path) -- cgit v1.2.3