From c29f46834139af02d046fe28ec1366101f080ec4 Mon Sep 17 00:00:00 2001 From: kbe Date: Sun, 20 Jul 2025 16:53:02 +0200 Subject: [PATCH 1/5] fix: no more version in compose --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 76c083c..b02ce63 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.8' services: crossfit-booker: From d7c5c987e82b2e9378e9fb4ee35d7dd087c8adac Mon Sep 17 00:00:00 2001 From: kbe Date: Sun, 20 Jul 2025 17:15:57 +0200 Subject: [PATCH 2/5] chore: moved organize preferred sessions by day --- crossfit_booker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crossfit_booker.py b/crossfit_booker.py index d17a9b1..3602f09 100644 --- a/crossfit_booker.py +++ b/crossfit_booker.py @@ -43,9 +43,9 @@ APP_VERSION = "5.09.21" # day_of_week: 0=Monday, 6=Sunday PREFERRED_SESSIONS = [ # (0, "17:00", "HYROX"), # Monday 17:00 HYROX + (2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING (4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING (5, "12:30", "HYROX"), # Saturday 12:30 HYROX - (2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING # (5, "15:15", "BIG WOD") # Saturday 15:15 BIG WOD ] From a4226e0c6b13c89917b9c1415f5ad0318f4e48f5 Mon Sep 17 00:00:00 2001 From: kbe Date: Sun, 20 Jul 2025 17:26:46 +0200 Subject: [PATCH 3/5] feat: preferred sessions are now external --- .gitignore | 2 ++ README.md | 48 ++++++++++++++++++++++++++++++++++++++++------ book_crossfit.py | 14 ++++++++++++++ crossfit_booker.py | 26 +++---------------------- 4 files changed, 61 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 753dc64..8da65ee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ .env log/ !log/.gitkeep +# Configuration files +preferred_sessions.json # Created by https://www.toptal.com/developers/gitignore/api/python # Edit at https://www.toptal.com/developers/gitignore?templates=python diff --git a/README.md b/README.md index d68a12d..cad7f7c 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,20 @@ docker-compose up --build The application will automatically check for available sessions and book them based on your preferences. It will send notifications via email and Telegram when a booking is successful. +### Configuring Preferred Sessions + +You can configure your preferred sessions using the `preferred_sessions.json` file. This file should contain a JSON array of session names, for example: + +```json +[ + "Morning Class", + "Evening Class", + "Saturday Open Gym" +] +``` + +If the file is not found or contains invalid data, the application will use default hardcoded sessions. + ### Environment Variables The following environment variables are required: @@ -44,16 +58,36 @@ The following environment variables are required: ### Preferred Sessions -You can configure your preferred sessions in the `crossfit_booker.py` file. The preferred sessions are defined as a list of tuples, where each tuple contains the day of the week, start time, and session name. +You can configure your preferred sessions in the `preferred_sessions.json` file. The preferred sessions are defined as a list of objects, where each object contains the day of the week, start time, and session name. -```python -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 +```json +[ + { + "day_of_week": 4, + "start_time": "17:00", + "session_name_contains": "WEIGHTLIFTING" + }, + { + "day_of_week": 5, + "start_time": "12:30", + "session_name_contains": "HYROX" + }, + { + "day_of_week": 2, + "start_time": "18:30", + "session_name_contains": "CONDITIONING" + } ] ``` +The application will automatically load the preferred sessions from this file. If the file is not found or contains invalid data, it will fall back to the default hardcoded sessions. + +#### Fields + +- `day_of_week`: Integer representing the day of the week (0=Monday, 6=Sunday) +- `start_time`: String representing the start time in HH:MM format +- `session_name_contains`: String containing the name or part of the name of the session + ## Files - `Dockerfile`: Docker image definition @@ -64,6 +98,7 @@ PREFERRED_SESSIONS = [ - `book_crossfit.py`: Main application script - `crossfit_booker.py`: Crossfit booking script - `session_notifier.py`: Session notification script +- `preferred_sessions.json`: Configuration file for preferred sessions - `requirements.txt`: Python dependencies ## Project Structure @@ -79,6 +114,7 @@ PREFERRED_SESSIONS = [ ├── crossfit_booker.py ├── session_notifier.py ├── requirements.txt +├── preferred_sessions.json └── log └── crossfit_booking.log ``` diff --git a/book_crossfit.py b/book_crossfit.py index 584a109..4e4ff21 100755 --- a/book_crossfit.py +++ b/book_crossfit.py @@ -4,6 +4,20 @@ import traceback from crossfit_booker import CrossFitBooker if __name__ == "__main__": + # Configure logging once at script startup + logging.basicConfig( + level=logging.DEBUG, # Change to DEBUG for more detailed logs + format='%(asctime)s - %(levelname)s - %(message)s', + handlers=[ + logging.FileHandler("log/crossfit_booking.log"), + logging.StreamHandler() + ] + ) + + logging.getLogger("requests").setLevel(logging.WARNING) + logging.info("Logging enhanced with request library noise reduction") + + # Start the main runner booker = CrossFitBooker() if not booker.login(): logging.error("Failed to login - Traceback: %s", traceback.format_exc()) diff --git a/crossfit_booker.py b/crossfit_booker.py index 3602f09..9d8d77e 100644 --- a/crossfit_booker.py +++ b/crossfit_booker.py @@ -18,6 +18,9 @@ from typing import List, Dict, Optional, Any # Import the SessionNotifier class from session_notifier import SessionNotifier +# Import the preferred sessions from the session_config module +from session_config import PREFERRED_SESSIONS + load_dotenv() # Configuration @@ -38,29 +41,6 @@ RETRY_MAX = 3 RETRY_BACKOFF = 1 APP_VERSION = "5.09.21" -# Define your preferred sessions -# Format: List of tuples (day_of_week, start_time, session_name_contains) -# day_of_week: 0=Monday, 6=Sunday -PREFERRED_SESSIONS = [ - # (0, "17:00", "HYROX"), # Monday 17:00 HYROX - (2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING - (4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING - (5, "12:30", "HYROX"), # Saturday 12:30 HYROX - # (5, "15:15", "BIG WOD") # Saturday 15:15 BIG WOD -] - -# Configure logging once at script startup -logging.basicConfig( - level=logging.DEBUG, # Change to DEBUG for more detailed logs - format='%(asctime)s - %(levelname)s - %(message)s', - handlers=[ - logging.FileHandler("log/crossfit_booking.log"), - logging.StreamHandler() - ] -) - -logging.getLogger("requests").setLevel(logging.WARNING) -logging.info("Logging enhanced with request library noise reduction") class CrossFitBooker: def __init__(self) -> None: From c437f908aca27755bdf43d54a41a8abed6def31b Mon Sep 17 00:00:00 2001 From: kbe Date: Sun, 20 Jul 2025 17:27:00 +0200 Subject: [PATCH 4/5] feat: preferred sessions are now external --- session_config.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 session_config.py diff --git a/session_config.py b/session_config.py new file mode 100644 index 0000000..99a4141 --- /dev/null +++ b/session_config.py @@ -0,0 +1,42 @@ +import json +import logging +from typing import List, Tuple + +# Class to handle session configuration +class SessionConfig: + """ + Class to handle loading and managing preferred sessions configuration. + """ + + @staticmethod + def load_preferred_sessions(): + """ + Load preferred sessions from a JSON file. + + Returns: + List[Tuple[int, str, str]]: List of preferred sessions in the format + (day_of_week, start_time, session_name_contains) + """ + preferred_sessions = [] + + try: + with open("preferred_sessions.json", "r") as f: + data = json.load(f) + for item in data: + day_of_week = item.get("day_of_week", 0) + start_time = item.get("start_time", "00:00") + session_name_contains = item.get("session_name_contains", "") + preferred_sessions.append((day_of_week, start_time, session_name_contains)) + except (FileNotFoundError, json.JSONDecodeError) as e: + logging.warning(f"Failed to load preferred sessions from file: {str(e)}") + # Fall back to default hardcoded sessions + # preferred_sessions = [ + # (2, "18:30", "CONDITIONING"), # Wednesday 18:30 CONDITIONING + # (4, "17:00", "WEIGHTLIFTING"), # Friday 17:00 WEIGHTLIFTING + # (5, "12:30", "HYROX"), # Saturday 12:30 HYROX + # ] + + return preferred_sessions + +# Load preferred sessions using the SessionConfig class +PREFERRED_SESSIONS = SessionConfig.load_preferred_sessions() \ No newline at end of file From a388b808f09b282dede59f9d4979cd2edf483823 Mon Sep 17 00:00:00 2001 From: kbe Date: Sun, 20 Jul 2025 17:28:05 +0200 Subject: [PATCH 5/5] feat: preferred sessions are now external --- .gitignore | 2 -- preferred_sessions.json | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 preferred_sessions.json diff --git a/.gitignore b/.gitignore index 8da65ee..753dc64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ .env log/ !log/.gitkeep -# Configuration files -preferred_sessions.json # Created by https://www.toptal.com/developers/gitignore/api/python # Edit at https://www.toptal.com/developers/gitignore?templates=python diff --git a/preferred_sessions.json b/preferred_sessions.json new file mode 100644 index 0000000..d327876 --- /dev/null +++ b/preferred_sessions.json @@ -0,0 +1,17 @@ +[ + { + "day_of_week": 2, + "start_time": "18:30", + "session_name_contains": "CONDITIONING" + }, + { + "day_of_week": 4, + "start_time": "17:00", + "session_name_contains": "WEIGHTLIFTING" + }, + { + "day_of_week": 5, + "start_time": "12:30", + "session_name_contains": "HYROX" + } +] \ No newline at end of file