refactored code to place the booking specific actions inside a gestion-sports element

This commit is contained in:
Stanislas Jouffroy 2024-02-21 23:49:33 +01:00
parent 1ec148e866
commit 552db2aa8a
3 changed files with 11 additions and 12 deletions

View file

@ -10,28 +10,28 @@ from pendulum import DateTime
LOGGER = logging.getLogger(__name__)
class GestionSportsOperations:
class GestionSportsPlatform:
def __init__(self, club: Club):
self.platform: GestionSportsConnector | None = None
self.connector: GestionSportsConnector | None = None
self.club: Club = club
self.session: ClientSession | None = None
async def __aenter__(self):
self.session = ClientSession()
self.platform = GestionSportsConnector(self.session, self.club.url)
self.connector = GestionSportsConnector(self.session, self.club.url)
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:
if self.platform is None or user is None or booking_filter is None:
if self.connector is None or user is None or booking_filter is None:
return None
await self.platform.land()
await self.platform.login(user, self.club)
await self.connector.land()
await self.connector.login(user, self.club)
wait_until_booking_time(self.club, booking_filter)
return await self.platform.book(booking_filter, self.club)
return await self.connector.book(booking_filter, self.club)
def wait_until_booking_time(club: Club, booking_filter: BookingFilter):