From: Max Value Date: Mon, 9 Dec 2024 22:26:55 +0000 (+0000) Subject: Fix on paths and added enviroment variables X-Git-Url: https://git.ozva.co.uk/?a=commitdiff_plain;h=e134942857121912583746c96ec423ce1b4877c8;p=critters-api Fix on paths and added enviroment variables Will help debug across systems, set by the wsgi script. --- diff --git a/critters.py b/critters.py index 399163b..e58ce35 100755 --- a/critters.py +++ b/critters.py @@ -24,11 +24,13 @@ current_track_id = Value("I") # This is the global track ID with current_track_id.get_lock(): current_track_id.value = 1 -audio_path = "/home/stream/critters/audio/" -cover_path = "/home/stream/critters/cover/" -icon_path = "/home/stream/critters/icon/" -upload_path = "/home/stream/critters/upload/" -template_path = "/home/stream/critters/critters-api/templates/" +critters_path = os.environ["CRITTERS_PATH"] +audio_path = critters_path + "/audio/" +cover_path = critters_path + "/cover/" +icon_path = critters_path + "/icon/" +upload_path = critters_path + "/upload/" +templates_path = critters_path + "/critters-api/templates/" +db_path = critters_path + "/../metadata.db" def check_files(track_id): return { @@ -43,7 +45,7 @@ def check_files(track_id): "icon_path": url_for("get_icon", track_id=track_id) } -with open("/home/stream/critters/secrets.json", "r") as f: +with open(critters_path + "/secrets.json", "r") as f: users = json.loads(f.read()) users = {k: generate_password_hash(v) for (k, v) in users.items()} @@ -56,7 +58,7 @@ def verify_password(username, password): # Homepage @app.route("/") def homepage(): - with open(template_path + "home.html","r") as f: + with open(templates_path + "home.html", "r") as f: page = render_template_string(f.read()) return Response(page, mimetype="text/html") @@ -65,7 +67,7 @@ def homepage(): @auth.login_required def admin(): if request.method == "POST": - con = sqlite3.connect("/home/stream/metadata.db") + con = sqlite3.connect(db_path) cur = con.cursor() try: commit_id = int(request.form["id"]) @@ -76,6 +78,8 @@ def admin(): else: playing = "false" + print(playing) + # Get the new track id if neccicary if commit_id == 0: tracks = cur.execute(f"SELECT id FROM critters").fetchall() @@ -165,7 +169,7 @@ def admin(): os.system(f"convert {file_path} -scale 32x32! {icon_path}{commit_id}.png &") os.system(f"convert {file_path} -scale 600x600! {cover_path}{commit_id}.png &") - with open(template_path + "admin.html", "r") as f: + with open(templates_path + "admin.html", "r") as f: page = render_template_string(f.read(), user = auth.current_user()) return Response(page, mimetype="text/html") @@ -187,7 +191,7 @@ def set_current_id(): current_album = "" current_artist = "" - con = sqlite3.connect("/home/stream/metadata.db") + con = sqlite3.connect(db_path) cur = con.cursor() track = cur.execute(f"SELECT album, artist FROM critters WHERE id={track_id}").fetchone() @@ -232,7 +236,7 @@ def get_tracks(): } responce_data = [track_data] - con = sqlite3.connect("/home/stream/metadata.db") + con = sqlite3.connect(db_path) cur = con.cursor() tracks = cur.execute(f"SELECT * FROM critters").fetchall() if tracks is not None: @@ -246,7 +250,7 @@ def get_single_track(track_id): if track_id == 0: with current_track_id.get_lock(): track_id = current_track_id.value - con = sqlite3.connect("/home/stream/metadata.db") + con = sqlite3.connect(db_path) cur = con.cursor() track = cur.execute(f"SELECT * FROM critters WHERE id={track_id}").fetchone() track_data = { @@ -274,7 +278,7 @@ def get_single_field(track_id, feild): track_id = current_track_id.value result = "Unknown" if feild in db_keys: - con = sqlite3.connect("/home/stream/metadata.db") + con = sqlite3.connect(db_path) cur = con.cursor() track = cur.execute(f"SELECT {feild} FROM critters WHERE id={track_id}").fetchone() if track is not None: