39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import asyncio
|
|
import logging
|
|
|
|
import config
|
|
from aiohttp import ClientSession
|
|
from gestion_sports.gestion_sports_connector import GestionSportsConnector
|
|
from models import BookingFilter, Club, User
|
|
|
|
LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
async def book(club: Club, user: User, booking_filter: BookingFilter) -> int | None:
|
|
async with ClientSession() as session:
|
|
platform = GestionSportsConnector(session, club.url)
|
|
await platform.connect()
|
|
await platform.login(user, club)
|
|
return await platform.book(booking_filter, club)
|
|
|
|
|
|
def main() -> int | None:
|
|
user = config.get_user()
|
|
booking_filter = config.get_booking_filter()
|
|
club = config.get_club()
|
|
|
|
LOGGER.info(
|
|
"Starting booking court of %s for user %s at club %s at %s",
|
|
booking_filter.sport_id,
|
|
user.login,
|
|
club.id,
|
|
booking_filter.date,
|
|
)
|
|
court_booked = asyncio.run(book(club, user, booking_filter))
|
|
if court_booked:
|
|
LOGGER.info(
|
|
"Court %s booked successfully at %s", court_booked, booking_filter.date
|
|
)
|
|
else:
|
|
LOGGER.info("Booking did not work")
|
|
return court_booked
|