webook / main.py
Mohammed Foud
Add application file
f959aff
from venv import logger
from login import WeBookLogin
from book import WeBookBooking
from utils import WeBookBase # Import WeBookBase for cleanup
from dotenv import load_dotenv
import os
# Load environment variables
load_dotenv()
def main():
profile_dir = "./webook_profile"
# Instantiate login and perform login
login = WeBookLogin(
email=os.getenv('WEBBOOK_EMAIL'),
password=os.getenv('WEBBOOK_PASSWORD'),
profile_dir=profile_dir
)
# login() now returns the page object on success, or False on failure
page = login.login()
if page: # Check if login was successful and returned a page object
logger.info("Login successful, proceeding with booking.")
# Instantiate booking with the existing page object
booking = WeBookBooking(page=page, profile_dir=profile_dir)
event_url = "https://webook.com/en/events/mdlbeast-beast-house-ec/book"
booking.book_event(event_url)
# Perform final cleanup using the context/playwright from the login object
# The page object is part of the context, so closing context is enough.
if login.context: # Check if context was created by login
login.context.close()
if login.playwright: # Check if playwright was started by login
login.playwright.stop()
logger.info("Browser closed after booking.")
else:
logger.error("Login failed. Cannot proceed with booking.")
# Cleanup should already be handled within login() on failure, but a final check
if login.context:
login.context.close()
if login.playwright:
login.playwright.stop()
if __name__ == "__main__":
main()