Can now book sessions if it not two days before

This commit is contained in:
kbe
2025-07-18 12:57:18 +02:00
parent 67ea86ed6f
commit f3702c5320
2 changed files with 16 additions and 13 deletions

View File

@@ -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)