Files
crossfit/main.py
2025-10-06 16:16:32 +02:00

77 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Main entry point for the CrossFit Booker application.
This script initializes the CrossFitBooker and starts the booking process.
"""
import logging
import os
from src.auth import AuthHandler
from src.booker import Booker
from src.session_notifier import SessionNotifier
# Load environment variables
from dotenv import load_dotenv
load_dotenv()
def main():
"""
Main function to initialize the Booker and start the booking process.
"""
# Set up logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.StreamHandler()
]
)
# Display ASCII art and username
try:
with open('ascii.md', 'r') as f:
ascii_art = f.read()
print(ascii_art, flush=True)
username = os.environ.get("CROSSFIT_USERNAME")
print(f"Username: {username}", flush=True)
print(flush=True)
except Exception as e:
logging.error(f"Error displaying ASCII: {e}")
# Initialize components
auth_handler = AuthHandler(
str(os.environ.get("CROSSFIT_USERNAME")),
str(os.environ.get("CROSSFIT_PASSWORD"))
)
# Initialize notification system
email_credentials = {
"from": os.environ.get("EMAIL_FROM"),
"to": os.environ.get("EMAIL_TO"),
"password": os.environ.get("EMAIL_PASSWORD")
}
telegram_credentials = {
"token": os.environ.get("TELEGRAM_TOKEN"),
"chat_id": os.environ.get("TELEGRAM_CHAT_ID")
}
enable_email = os.environ.get("ENABLE_EMAIL_NOTIFICATIONS", "true").lower() in ("true", "1", "yes")
enable_telegram = os.environ.get("ENABLE_TELEGRAM_NOTIFICATIONS", "true").lower() in ("true", "1", "yes")
notifier = SessionNotifier(
email_credentials,
telegram_credentials,
enable_email=enable_email,
enable_telegram=enable_telegram
)
# Initialize the Booker
booker = Booker(auth_handler, notifier)
# Run the booking process
import asyncio
asyncio.run(booker.run())
if __name__ == "__main__":
main()