Skip to content

Commit

Permalink
Refactor code to include last_time variable in main.py and remove red…
Browse files Browse the repository at this point in the history
…undant code in rpc.py
  • Loading branch information
zeroquinc committed Jan 27, 2024
1 parent 3ff32c6 commit db53917
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down
6 changes: 0 additions & 6 deletions src/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit db53917

Please sign in to comment.