Preserve backup_old_docker bot variant at root (for comparison)

Snapshot of the dockerisation-era bot code laid out at the repository
root so it can be diffed directly against the working-copy baseline
(restructure/working-copy-root) to see how the variant differed:

- thin_client.py asyncio entrypoint (vs working_copy bot.py)
- constants.py env-var/credential refactor, communication auth, etc.
- extra gpt_interface/ service, sync.py, watch_script_params.py
- conanjurer_* modules absent in this variant

Docker infrastructure (docker/, docker-compose.yml, .dockerignore)
intentionally omitted - this branch is for code comparison only and is
not intended to be merged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Michal Tuszowski
2026-06-28 22:55:53 +02:00
parent f9a1e7c03a
commit ef6eb84921
33 changed files with 1074 additions and 536 deletions
+44 -11
View File
@@ -1,15 +1,17 @@
import json
import logging
import os
import re
import threading
import time
from queue import Empty, Queue
from typing import Optional
from urllib import request as urequest
from flask import Flask, jsonify, request
from flask import Flask, abort, jsonify, request
from waitress import serve
HOST_ADDRESS = "192.168.1.31"
HOST_ADDRESS = "192.168.1.191"
PORT_ADDRESS = 5000
ICECAST_ADDRESS = "http://192.168.1.15:8000"
OUT_COMM_Q = Queue()
@@ -31,6 +33,13 @@ PREPPED_TRACKS = {
}
logger = logging.getLogger("discord")
API_KEY = os.getenv("CONJURER_API_KEY")
def _authorize_request() -> None:
if API_KEY and request.headers.get("X-Conjurer-Api-Key") != API_KEY:
abort(401)
class QueryControl:
"""
@@ -53,6 +62,7 @@ class QueryControl:
@app.route("/prepped_tracks", methods=["POST"])
def log_radio_tracks():
_authorize_request()
app.logger = logging.getLogger("discord")
app.logger.info(request)
@@ -79,6 +89,7 @@ def log_radio_tracks():
@app.route("/conjurer", methods=["POST"])
def answer_external_command():
_authorize_request()
"""
The function `answer_external_command` logs the request data, loads the data as JSON, logs the
record, and then puts the record into an incoming queue before returning a success message.
@@ -129,7 +140,7 @@ def waitress_run():
serve(app, host=HOST_ADDRESS, port=PORT_ADDRESS)
def scan_queue():
def scan_queue(stop_event: Optional[threading.Event] = None):
"""
The function `scan_queue` reads data from a queue, logs it, and appends it to another queue.
@@ -140,12 +151,18 @@ def scan_queue():
"""
logger = logging.getLogger("discord")
while True:
data = OUT_COMM_Q.get()
if stop_event and stop_event.is_set():
logger.info("scan_queue: stop requested")
break
try:
data = OUT_COMM_Q.get(timeout=1)
except Empty:
continue
logger.info(data)
awaiting_q.append(data)
def scan_incoming():
def scan_incoming(stop_event: Optional[threading.Event] = None):
"""
The `scan_incoming` function continuously checks for incoming data, processes it, and logs when data
is found.
@@ -157,6 +174,9 @@ def scan_incoming():
"""
logger = logging.getLogger("discord")
while True:
if stop_event and stop_event.is_set():
logger.info("scan_incoming: stop requested")
break
try:
answer = incoming_q.get(block=False)
logger.info("DATA FOUND")
@@ -204,7 +224,7 @@ def id3(url: str) -> dict:
return tagdata
def comm_subroutine():
def comm_subroutine(stop_event: Optional[threading.Event] = None):
"""
The `comm_subroutine` function starts multiple threads to run different tasks concurrently.
@@ -217,14 +237,27 @@ def comm_subroutine():
logger.info("Started comms")
threads = []
# threads.append(threading.Thread(target=flask_debug))
threads.append(threading.Thread(target=waitress_run))
threads.append(threading.Thread(target=scan_queue))
threads.append(threading.Thread(target=scan_incoming))
threads.append(
threading.Thread(target=waitress_run, daemon=True)
)
threads.append(
threading.Thread(target=scan_queue, kwargs={"stop_event": stop_event}, daemon=True)
)
threads.append(
threading.Thread(target=scan_incoming, kwargs={"stop_event": stop_event}, daemon=True)
)
for worker in threads:
worker.start()
for worker in threads:
worker.join()
try:
while any(thread.is_alive() for thread in threads):
if stop_event and stop_event.is_set():
break
time.sleep(0.5)
finally:
if stop_event:
stop_event.set()
if __name__ == "__main__":