chore: remove duplicate code and add env vars

This commit is contained in:
kbe
2025-07-18 15:39:20 +02:00
parent a09a7d6bd1
commit 6c2adad760
2 changed files with 11 additions and 52 deletions

3
.env.example Normal file
View File

@@ -0,0 +1,3 @@
# Configuration
CROSSFIT_USERNAME=Kevin8407
CROSSFIT_PASSWORD=9vx03OSE

View File

@@ -12,12 +12,16 @@ from urllib.parse import urlencode
from typing import List, Dict, Optional
# Configuration
USERNAME = "Kevin8407"
PASSWORD = "9vx03OSE"
USERNAME = os.environ.get('CROSSFIT_USERNAME')
PASSWORD = os.environ.get('CROSSFIT_PASSWORD')
if not all([USERNAME, PASSWORD]):
raise ValueError("Missing environment variables: CROSSFIT_USERNAME and/or CROSSFIT_PASSWORD")
APPLICATION_ID = "81560887"
CATEGORY_ID = "677" # Activity category ID for CrossFit
TIMEZONE = "Europe/Paris" # Adjust to your timezone
TARGET_RESERVATION_TIME = "20:00" # When bookings open (8 PM)
TARGET_RESERVATION_TIME = "20:01" # When bookings open (8 PM)
DEVICE_TYPE = "3"
APP_VERSION = "5.09.21"
@@ -166,55 +170,6 @@ class CrossFitBooker:
print(f"Unexpected error: {str(e)}")
return None
try:
# Debug output
# print("\n--- Request Details ---")
# print(f"URL: {url}")
# print(f"Headers: {json.dumps(self.get_auth_headers(), indent=2)}")
# print(f"Payload: {request_data}")
# Make the request
response = self.session.post(
url,
headers=self.get_auth_headers(),
data=urlencode(request_data),
timeout=10
)
# Debug raw response
# print("\n--- Response ---")
# print(f"Status Code: {response.status_code}")
# print(f"Headers: {response.headers}")
# print(f"Content: {response.text}")
# Handle response
if response.status_code == 200:
try:
json_response = response.json()
return json_response
except ValueError:
print("Failed to decode JSON response")
return None
elif response.status_code == 400:
print("400 Bad Request - likely missing or invalid parameters")
print("Verify these parameters:")
for param, value in request_data.items():
print(f"- {param}: {value}")
return None
elif response.status_code == 401:
print("401 Unauthorized - token may be expired or invalid")
return None
else:
print(f"Unexpected status code: {response.status_code}")
return None
except requests.exceptions.RequestException as e:
print(f"Request failed: {str(e)}")
return None
except Exception as e:
print(f"Unexpected error: {str(e)}")
return None
def book_session(self, session_id: str) -> bool:
"""Book a specific session with debug logging."""
print(f"\n[INFO] Attempting to book session_id: {session_id}")
@@ -429,3 +384,4 @@ if __name__ == "__main__":
booker.book_session(session.get("id_activity_calendar"))