diff options
| author | Arslaan Pathan <[email protected]> | 2026-10-06 08:34:47 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-10-06 08:34:47 +1300 |
| commit | c03f2c4d645a1b36e4038cec933ded31546729af (patch) | |
| tree | c83d90387bb0f49ae01b452d2a95d21b78903db1 /backend.py | |
| parent | bbab545a8475d711a486afb0d47c561efb4434c3 (diff) | |
| download | remote-automation-c03f2c4d645a1b36e4038cec933ded31546729af.tar.xz remote-automation-c03f2c4d645a1b36e4038cec933ded31546729af.zip | |
print queue
Diffstat (limited to 'backend.py')
| -rw-r--r-- | backend.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -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" [email protected]("/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) |
