Can now book sessions if it not two days before
This commit is contained in:
@@ -4,6 +4,9 @@ import requests
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
# Parse session time (handles timezones if present)
|
||||||
|
from dateutil.parser import parse
|
||||||
import pytz
|
import pytz
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
from typing import List, Dict, Optional
|
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)
|
# Format: List of tuples (day_of_week, start_time, session_name_contains)
|
||||||
# day_of_week: 0=Monday, 6=Sunday
|
# day_of_week: 0=Monday, 6=Sunday
|
||||||
PREFERRED_SESSIONS = [
|
PREFERRED_SESSIONS = [
|
||||||
(4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING
|
(4, "17:00", "WEIGHTLIFTING"),
|
||||||
(5, "12:30", "HYROX"), # Saturday 12:30 HYROX
|
(5, "12:30", "HYROX"),
|
||||||
(2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING
|
(2, "18:30", "CONDITIONING"),
|
||||||
|
(5, "15:15", "BIG WOD") # Changed to uppercase
|
||||||
]
|
]
|
||||||
|
|
||||||
class CrossFitBooker:
|
class CrossFitBooker:
|
||||||
@@ -271,16 +275,12 @@ class CrossFitBooker:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def matches_preferred_session(self, session: Dict, current_time: datetime) -> bool:
|
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:
|
try:
|
||||||
session_time = datetime.strptime(session["start_timestamp"], "%Y-%m-%d %H:%M:%S")
|
session_time = parse(session["start_timestamp"])
|
||||||
|
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 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
|
|
||||||
|
|
||||||
# Get day of week (0=Monday, 6=Sunday) and time
|
# Get day of week (0=Monday, 6=Sunday) and time
|
||||||
day_of_week = session_time.weekday()
|
day_of_week = session_time.weekday()
|
||||||
session_time_str = session_time.strftime("%H:%M")
|
session_time_str = session_time.strftime("%H:%M")
|
||||||
@@ -290,7 +290,7 @@ class CrossFitBooker:
|
|||||||
for preferred_day, preferred_time, preferred_name in PREFERRED_SESSIONS:
|
for preferred_day, preferred_time, preferred_name in PREFERRED_SESSIONS:
|
||||||
if (day_of_week == preferred_day and
|
if (day_of_week == preferred_day and
|
||||||
session_time_str == preferred_time and
|
session_time_str == preferred_time and
|
||||||
preferred_name in session_name):
|
preferred_name in session_name): # Partial match
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -392,10 +392,11 @@ if __name__ == "__main__":
|
|||||||
# if booker.is_session_bookable(session, session_time):
|
# if booker.is_session_bookable(session, session_time):
|
||||||
bookable_sessions.append(session)
|
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")
|
print(f"\nFound {len(bookable_sessions)} sessions to book")
|
||||||
|
|
||||||
|
|
||||||
for session in bookable_sessions:
|
for session in bookable_sessions:
|
||||||
results = booker.matches_preferred_session(session, current_time)
|
results = booker.matches_preferred_session(session, current_time)
|
||||||
|
print(session.get("name_activity"))
|
||||||
print(results)
|
print(results)
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ certifi==2025.7.14
|
|||||||
charset-normalizer==3.4.2
|
charset-normalizer==3.4.2
|
||||||
DateTime==5.5
|
DateTime==5.5
|
||||||
idna==3.10
|
idna==3.10
|
||||||
|
python-dateutil==2.9.0.post0
|
||||||
pytz==2025.2
|
pytz==2025.2
|
||||||
requests==2.32.4
|
requests==2.32.4
|
||||||
setuptools==80.9.0
|
setuptools==80.9.0
|
||||||
|
six==1.17.0
|
||||||
typing==3.7.4.3
|
typing==3.7.4.3
|
||||||
urllib3==2.5.0
|
urllib3==2.5.0
|
||||||
zope.interface==7.2
|
zope.interface==7.2
|
||||||
|
|||||||
Reference in New Issue
Block a user