Big refactoring.
- clubs, booking platforms and user are now defined in customization files -> there are less environment variables - the responsibility of the session moved - booking cancellation is available
This commit is contained in:
parent
dbda5a158e
commit
0938fb98b7
27 changed files with 3050 additions and 696 deletions
42
resa_padel/booking_service.py
Normal file
42
resa_padel/booking_service.py
Normal file
|
@ -0,0 +1,42 @@
|
|||
import logging
|
||||
|
||||
from aiohttp import ClientSession
|
||||
from connectors import Connector
|
||||
from models import BookingFilter, Club, User
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class BookingService:
|
||||
def __init__(self, club: Club, connector: Connector):
|
||||
LOGGER.info("Initializing booking service at for club", club.name)
|
||||
self.club = club
|
||||
self.connector = connector
|
||||
self.session: ClientSession | None = None
|
||||
|
||||
async def __aenter__(self):
|
||||
self.session = ClientSession()
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
await self.session.close()
|
||||
|
||||
async def book(self, user: User, booking_filter: BookingFilter) -> int | None:
|
||||
"""
|
||||
Book a court matching the booking filters for a user.
|
||||
The steps to perform a booking are to go to the landing page, to log in, wait
|
||||
and for the time when booking is open and then actually book the court
|
||||
|
||||
:param user: the user that wants to book a court
|
||||
:param booking_filter: the booking criteria
|
||||
:return: the court number if the booking is successful, None otherwise
|
||||
"""
|
||||
if self.connector is None:
|
||||
LOGGER.error("No connection to Gestion Sports is available")
|
||||
return None
|
||||
|
||||
if user is None or booking_filter is None:
|
||||
LOGGER.error("Not enough information available to book a court")
|
||||
return None
|
||||
|
||||
self.connector.book(user, booking_filter)
|
Loading…
Add table
Add a link
Reference in a new issue