diff --git a/crossfit_booker.py b/crossfit_booker.py index 286fe36..cdc3fb4 100644 --- a/crossfit_booker.py +++ b/crossfit_booker.py @@ -444,9 +444,9 @@ class CrossFitBooker: Args: current_time (datetime): Current time for comparison. """ - # Calculate date range to check (next 3 days) + # Calculate date range to check (current day, day + 1, and day + 2) start_date: date = current_time.date() - end_date: date = start_date + timedelta(days=3) + end_date: date = start_date + timedelta(days=2) # Only go up to day + 2 # Get available sessions sessions_data: Optional[Dict[str, Any]] = self.get_available_sessions(start_date, end_date) @@ -456,7 +456,7 @@ class CrossFitBooker: activities: List[Dict[str, Any]] = sessions_data.get("data", {}).get("activities_calendar", []) - # Find sessions to book (preferred only) + # Find sessions to book (preferred only) within allowed date range sessions_to_book: List[Tuple[str, Dict[str, Any]]] = [] upcoming_sessions: List[Dict[str, Any]] = [] found_preferred_sessions: List[Dict[str, Any]] = [] @@ -466,6 +466,11 @@ class CrossFitBooker: if not session_time.tzinfo: session_time = pytz.timezone(TIMEZONE).localize(session_time) + # Check if session is within allowed date range (current day, day + 1, or day + 2) + days_diff = (session_time.date() - current_time.date()).days + if not (0 <= days_diff <= 2): + continue # Skip sessions outside the allowed date range + # Check if session is preferred and bookable if self.is_session_bookable(session, current_time): if self.matches_preferred_session(session, current_time): @@ -475,8 +480,8 @@ class CrossFitBooker: # Check if it's a preferred session that's not bookable yet if self.matches_preferred_session(session, current_time): found_preferred_sessions.append(session) - # Check if it's available tomorrow - if (session_time.date() - current_time.date()).days == 1: + # Check if it's available tomorrow (day + 1) + if days_diff == 1: upcoming_sessions.append(session) if not sessions_to_book and not upcoming_sessions: