diff --git a/src/booker.py b/src/booker.py index 8fb07a8..ceb9cc1 100644 --- a/src/booker.py +++ b/src/booker.py @@ -192,8 +192,6 @@ class Booker: # Parse TARGET_RESERVATION_TIME to get the target hour and minute target_hour, target_minute = map(int, TARGET_RESERVATION_TIME.split(":")) - target_time = datetime.now(tz).replace(hour=target_hour, minute=target_minute, second=0, microsecond=0) - booking_window_end = target_time + timedelta(minutes=BOOKING_WINDOW_END_DELTA_MINUTES) # Initial login if not self.auth_handler.login(): @@ -206,15 +204,19 @@ class Booker: current_time: datetime = datetime.now(tz) logging.info(f"Current time: {current_time}") + # Recalculate target time and end time for the current day + today_target_time = current_time.replace(hour=target_hour, minute=target_minute, second=0, microsecond=0) + booking_window_end = today_target_time + timedelta(minutes=BOOKING_WINDOW_END_DELTA_MINUTES) + # Only book sessions if current time is within the booking window - if target_time <= current_time <= booking_window_end: + if today_target_time <= current_time <= booking_window_end: # Run booking cycle to check for preferred sessions and book await self.booker(current_time) # Wait for a short time before next check time.sleep(60) else: # Display message when outside booking window - # logging.info(f"Not booking now - current time {current_time} is outside the booking window ({target_time} to {booking_window_end})") + # logging.info(f"Not booking now - current time {current_time} is outside the booking window ({today_target_time} to {booking_window_end})") # Check again in 5 minutes if outside booking window time.sleep(300) except Exception as e: