feat: only book session in current day, +1 and +2

This commit is contained in:
kbe
2025-07-24 12:06:42 +02:00
parent cacdd74184
commit cf4780d9d0

View File

@@ -444,9 +444,9 @@ class CrossFitBooker:
Args: Args:
current_time (datetime): Current time for comparison. 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() 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 # Get available sessions
sessions_data: Optional[Dict[str, Any]] = self.get_available_sessions(start_date, end_date) 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", []) 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]]] = [] sessions_to_book: List[Tuple[str, Dict[str, Any]]] = []
upcoming_sessions: List[Dict[str, Any]] = [] upcoming_sessions: List[Dict[str, Any]] = []
found_preferred_sessions: List[Dict[str, Any]] = [] found_preferred_sessions: List[Dict[str, Any]] = []
@@ -466,6 +466,11 @@ class CrossFitBooker:
if not session_time.tzinfo: if not session_time.tzinfo:
session_time = pytz.timezone(TIMEZONE).localize(session_time) 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 # Check if session is preferred and bookable
if self.is_session_bookable(session, current_time): if self.is_session_bookable(session, current_time):
if self.matches_preferred_session(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 # Check if it's a preferred session that's not bookable yet
if self.matches_preferred_session(session, current_time): if self.matches_preferred_session(session, current_time):
found_preferred_sessions.append(session) found_preferred_sessions.append(session)
# Check if it's available tomorrow # Check if it's available tomorrow (day + 1)
if (session_time.date() - current_time.date()).days == 1: if days_diff == 1:
upcoming_sessions.append(session) upcoming_sessions.append(session)
if not sessions_to_book and not upcoming_sessions: if not sessions_to_book and not upcoming_sessions: