From db53917e0ca99794427c34fbc686dfcb668545f4 Mon Sep 17 00:00:00 2001 From: zeroquinc Date: Sat, 27 Jan 2024 12:49:41 +0100 Subject: [PATCH] Refactor code to include last_time variable in main.py and remove redundant code in rpc.py --- main.py | 6 +++--- src/rpc.py | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 04d581d..6762443 100644 --- a/main.py +++ b/main.py @@ -12,16 +12,16 @@ def main(): try: with requests.Session() as session: - last_info, last_length = None, None + last_info, last_length, last_time = None, None, None while True: info = fetch_info(session) length = fetch_length(session) if info is None or length is None: # If either info or length is None, continue to the next iteration time.sleep(3) continue - if info != last_info or length != last_length: + if info != last_info or length != last_length or (length['result']['speed'] == 1 and length['result']['time'] == last_time): update_rp(info, length) # Update the RP if there's new information - last_info, last_length = info, length # Update the last info and length + last_info, last_length, last_time = info, length, last_time # Update the last info and length time.sleep(3) # Always pause for 3 seconds between iterations except KeyboardInterrupt: logger.info("Program interrupted by user. Exiting...") diff --git a/src/rpc.py b/src/rpc.py index 93a7c2d..1bf7a99 100644 --- a/src/rpc.py +++ b/src/rpc.py @@ -239,12 +239,6 @@ def calculate_start_time(length): def calculate_end_time(start_time, length): start_time = datetime.fromtimestamp(start_time) end_time = (start_time + timedelta(hours=length['totaltime']['hours'], minutes=length['totaltime']['minutes'], seconds=length['totaltime']['seconds'])).timestamp() - - # If start_time and end_time are the same, fetch length again - while start_time == end_time: - length = fetch_length() # Assuming fetch_length() is a function that fetches the length - end_time = (start_time + timedelta(hours=length['totaltime']['hours'], minutes=length['totaltime']['minutes'], seconds=length['totaltime']['seconds'])).timestamp() - return end_time # Function to create the buttons for a media