From a827c5e429bfd812d5355e13bacad92f457c3b1b Mon Sep 17 00:00:00 2001 From: mtuszowski Date: Fri, 2 Aug 2024 19:22:25 +0200 Subject: [PATCH] Fix tracker --- communication_subroutine.py | 2 -- conjurer_musician/conjurer_musician.py | 28 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/communication_subroutine.py b/communication_subroutine.py index e30d94d..77122f3 100644 --- a/communication_subroutine.py +++ b/communication_subroutine.py @@ -47,8 +47,6 @@ def log_radio_tracks(): logger.info(request) record = json.loads(request.data) logger.info(record) - PREPPED_TRACKS["now_playing"] = "" - PREPPED_TRACKS["now_playing"] = PREPPED_TRACKS[record[0]] PREPPED_TRACKS[record[0]] = record[1] logger.info("DATA RECEIVED") return jsonify("SUCCESS") diff --git a/conjurer_musician/conjurer_musician.py b/conjurer_musician/conjurer_musician.py index aded752..18ff084 100644 --- a/conjurer_musician/conjurer_musician.py +++ b/conjurer_musician/conjurer_musician.py @@ -32,6 +32,7 @@ if platform in ("linux", "linux2"): LOGSTORE = "/home/mtuszowski/conjurer/logs/" ENCODING = "utf-8" RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log' + PERSISTENCE_PATH = '/home/pi/Conjurer/persistence.log' else: LOGFILE = "/home/pi/Conjurer/discord_mus_service.log" @@ -41,6 +42,7 @@ if platform in ("linux", "linux2"): MUSIC_FOLDER = "/home/pi/RetroPie/mp3/" PRIORITY_FOLDER = "/home/pi/RetroPie/mp3/Magiczne i chuj/" RADIOLOG_PATH = '/home/pi/Conjurer/radio_log.log' + PERSISTENCE_PATH = '/home/pi/Conjurer/persistence.log' music_file_list = [] @@ -102,13 +104,31 @@ def scan_tracks(): logger = logging.getLogger("conjurer_musician") file = open(RADIOLOG_PATH,'r') - #Find the size of the file and move to the end st_results = os.stat(RADIOLOG_PATH) st_size = st_results[6] file.seek(st_size) + st_results1 = os.stat(PERSISTENCE_PATH) + prev_st_size1 = st_results[6] while 1: + + st_results1 = os.stat(PERSISTENCE_PATH) + st_size1 = st_results1[6] + if prev_st_size1 != st_size1: + prev_st_size1 = st_size1 + file1 = open(PERSISTENCE_PATH, 'r') + lines = file1.getlines() + result = ["now_playing", lines[3]] + file1.close() + returned = requests.post( + f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", + json=result, + timeout=360) + logger.info("SENT") + logger.info(returned.status_code) + logger.info("SEND CONFIRMED") + where = file.tell() line = file.readline() if not line: @@ -142,9 +162,9 @@ def scan_tracks(): f"{MAIN_BOT_ADDRESS}{MUSIC_TRACKER}", json=result, timeout=360) - logger.info("SENT") - logger.info(returned.status_code) - logger.info("SEND CONFIRMED") + logger.info("SENT") + logger.info(returned.status_code) + logger.info("SEND CONFIRMED") time.sleep(0.1)