diff --git a/crossfit_booker.py b/crossfit_booker.py index c725d72..d953fd0 100644 --- a/crossfit_booker.py +++ b/crossfit_booker.py @@ -424,10 +424,6 @@ class CrossFitBooker: # Display all available sessions within the date range self.display_upcoming_sessions(activities, current_time) - # Display preferred sessions found - - # Display booked session(s) - # Find sessions to book (preferred only) within allowed date range found_preferred_sessions: List[Dict[str, Any]] = [] @@ -446,29 +442,57 @@ class CrossFitBooker: if self.matches_preferred_session(session, current_time): found_preferred_sessions.append(session) + # Display preferred sessions found + if found_preferred_sessions: + logging.info("Preferred sessions found:") + for session in found_preferred_sessions: + session_time: datetime = parse(session["start_timestamp"]) + if not session_time.tzinfo: + session_time = pytz.timezone(TIMEZONE).localize(session_time) + logging.info(f"ID: {session['id_activity_calendar']}, Name: {session['name_activity']}, Time: {session_time.strftime('%Y-%m-%d %H:%M')}") + else: + logging.info("No matching preferred sessions found") + + # Book preferred sessions if not found_preferred_sessions: logging.info("No matching sessions found to book") return # Book sessions (preferred first) - sessions_to_book = [(("Preferred", session) for session in found_preferred_sessions)] + sessions_to_book = [("Preferred", session) for session in found_preferred_sessions] sessions_to_book.sort(key=lambda x: 0 if x[0] == "Preferred" else 1) + booked_sessions = [] + for session_type, session in sessions_to_book: - session_time: datetime = datetime.strptime(session["start_timestamp"], "%Y-%m-%d %H:%M:%S") + session_time: datetime = parse(session["start_timestamp"]) logging.info(f"Attempting to book {session_type} session at {session_time} ({session['name_activity']})") if self.book_session(session["id_activity_calendar"]): - # Send notification after successful booking + # Display booked session + booked_sessions.append(session) + logging.info(f"Successfully booked {session_type} session at {session_time}") + + # Notify about booked session session_details = f"{session['name_activity']} at {session_time.strftime('%Y-%m-%d %H:%M')}" await self.notifier.notify_session_booking(session_details) - logging.info(f"Successfully booked {session_type} session at {session_time}") else: logging.error(f"Failed to book {session_type} session at {session_time}") - # Send notification about the failed booking + + # Notify about failed booking session_details = f"{session['name_activity']} at {session_time.strftime('%Y-%m-%d %H:%M')}" await self.notifier.notify_impossible_booking(session_details) logging.info(f"Notified about impossible booking for {session_type} session at {session_time}") - + # Display all booked session(s) + if booked_sessions: + logging.info("Booked sessions:") + for session in booked_sessions: + session_time: datetime = parse(session["start_timestamp"]) + if not session_time.tzinfo: + session_time = pytz.timezone(TIMEZONE).localize(session_time) + logging.info(f"ID: {session['id_activity_calendar']}, Name: {session['name_activity']}, Time: {session_time.strftime('%Y-%m-%d %H:%M')}") + else: + logging.info("No sessions were booked") + async def run(self) -> None: """ Main execution loop.