|
|
import time |
|
|
from utils import WeBookBase, logger |
|
|
|
|
|
class WeBookBooking(WeBookBase): |
|
|
def __init__(self, page, profile_dir=None): |
|
|
super().__init__(profile_dir, page=page) |
|
|
if not self.page: |
|
|
raise ValueError("A Playwright page object must be provided to WeBookBooking") |
|
|
|
|
|
def book_event(self, event_url): |
|
|
try: |
|
|
logger.info(f"Navigating to event booking page: {event_url}") |
|
|
self.page.goto(event_url, wait_until='networkidle') |
|
|
|
|
|
self._handle_cookies() |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
plus_button = self.page.locator('button:has(svg path[d="M7 1C7 0.447715 6.55228 0 6 0C5.44772 0 5 0.447715 5 1V5H1C0.447715 5 0 5.44772 0 6C0 6.55228 0.447715 7 1 7H5V11C5 11.5523 5.44772 12 6 12C6.55228 12 7 11.5523 7 11V7H11C11.5523 7 12 6.55228 12 6C12 5.44772 11.5523 5 11 5H7V1Z"])').first |
|
|
|
|
|
if plus_button.is_visible(): |
|
|
plus_button.click() |
|
|
logger.info("Clicked '+' button (SVG) for the first ticket offer") |
|
|
|
|
|
|
|
|
|
|
|
summary_button = self.page.locator('[data-testid="ticketing_tickets_go_to_summary_button"]') |
|
|
summary_button.wait_for(state='visible', timeout=5000) |
|
|
|
|
|
else: |
|
|
logger.warning("Could not find the '+' button (SVG) for ticket selection.") |
|
|
return False |
|
|
|
|
|
except Exception as click_e: |
|
|
logger.error(f"Failed to click '+' button (SVG) or wait for summary button: {str(click_e)}") |
|
|
return False |
|
|
|
|
|
|
|
|
if summary_button.is_visible(): |
|
|
summary_button.click() |
|
|
logger.info("Clicked main summary/payment button (using data-testid)") |
|
|
|
|
|
|
|
|
|
|
|
skip_button = self.page.get_by_role("button", name="Skip to checkout") |
|
|
try: |
|
|
skip_button.wait_for(state='visible', timeout=5000) |
|
|
if skip_button.is_visible(): |
|
|
skip_button.click() |
|
|
logger.info("Clicked 'Skip to Payment' button") |
|
|
else: |
|
|
logger.warning("'Skip to Payment' button not visible after waiting.") |
|
|
return False |
|
|
except Exception as skip_e: |
|
|
logger.error(f"Failed to wait for or click 'Skip to Payment' button: {str(skip_e)}") |
|
|
return False |
|
|
|
|
|
|
|
|
else: |
|
|
logger.warning("Main summary/payment button not visible after waiting.") |
|
|
return False |
|
|
|
|
|
|
|
|
terms_checkbox = self.page.locator('[data-testid="ticketing_summary_resell_terms_checkbox"]') |
|
|
if terms_checkbox.is_visible(): |
|
|
terms_checkbox.click() |
|
|
logger.info("Accepted terms and conditions") |
|
|
else: |
|
|
logger.warning("Could not find the terms checkbox.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
confirm_button = self.page.locator('[data-testid="ticketing_summary_proceed_to_payment"]') |
|
|
try: |
|
|
confirm_button.wait_for(state='visible', timeout=5000) |
|
|
if confirm_button.is_visible(): |
|
|
confirm_button.click() |
|
|
logger.info("Clicked 'Confirm & pay' button") |
|
|
else: |
|
|
logger.warning("'Confirm & pay' button not visible after waiting.") |
|
|
return False |
|
|
except Exception as confirm_e: |
|
|
logger.error(f"Failed to wait for or click 'Confirm & pay' button: {str(confirm_e)}") |
|
|
return False |
|
|
|
|
|
time.sleep(330) |
|
|
|
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
logger.error(f"Booking process failed: {str(e)}") |
|
|
return False |