diff --git a/book_crossfit.py b/book_crossfit.py index 727a909..24b7ad5 100755 --- a/book_crossfit.py +++ b/book_crossfit.py @@ -4,6 +4,9 @@ import requests import json import time from datetime import datetime, timedelta + +# Parse session time (handles timezones if present) +from dateutil.parser import parse import pytz from urllib.parse import urlencode from typing import List, Dict, Optional @@ -22,9 +25,10 @@ APP_VERSION = "5.09.21" # Format: List of tuples (day_of_week, start_time, session_name_contains) # day_of_week: 0=Monday, 6=Sunday PREFERRED_SESSIONS = [ - (4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING - (5, "12:30", "HYROX"), # Saturday 12:30 HYROX - (2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING + (4, "17:00", "WEIGHTLIFTING"), + (5, "12:30", "HYROX"), + (2, "18:30", "CONDITIONING"), + (5, "15:15", "BIG WOD") # Changed to uppercase ] class CrossFitBooker: @@ -271,15 +275,11 @@ class CrossFitBooker: return False def matches_preferred_session(self, session: Dict, current_time: datetime) -> bool: - """Check if session matches one of your preferred sessions""" + """Check if session matches one of your preferred sessions.""" try: - session_time = datetime.strptime(session["start_timestamp"], "%Y-%m-%d %H:%M:%S") - session_time = pytz.timezone(TIMEZONE).localize(session_time) - - # Check if session is exactly 2 days from now - two_days_from_now = current_time + timedelta(days=2) - if session_time.date() != two_days_from_now.date(): - return False + session_time = parse(session["start_timestamp"]) + if not session_time.tzinfo: + session_time = pytz.timezone(TIMEZONE).localize(session_time) # Get day of week (0=Monday, 6=Sunday) and time day_of_week = session_time.weekday() @@ -290,7 +290,7 @@ class CrossFitBooker: for preferred_day, preferred_time, preferred_name in PREFERRED_SESSIONS: if (day_of_week == preferred_day and session_time_str == preferred_time and - preferred_name in session_name): + preferred_name in session_name): # Partial match return True return False @@ -392,10 +392,11 @@ if __name__ == "__main__": # if booker.is_session_bookable(session, session_time): bookable_sessions.append(session) - print(f"Bookable sessions: {json.dumps(bookable_sessions, indent=2)}") + # print(f"Bookable sessions: {json.dumps(bookable_sessions, indent=2)}") print(f"\nFound {len(bookable_sessions)} sessions to book") for session in bookable_sessions: results = booker.matches_preferred_session(session, current_time) + print(session.get("name_activity")) print(results) diff --git a/requirements.txt b/requirements.txt index 2c82111..c8ba662 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,11 @@ certifi==2025.7.14 charset-normalizer==3.4.2 DateTime==5.5 idna==3.10 +python-dateutil==2.9.0.post0 pytz==2025.2 requests==2.32.4 setuptools==80.9.0 +six==1.17.0 typing==3.7.4.3 urllib3==2.5.0 zope.interface==7.2