fix Screenshotter

This commit is contained in:
2026-03-21 18:21:46 +01:00
parent 86e0bc8e51
commit e94d96f153

View File

@@ -1,3 +1,4 @@
import time
from pathlib import Path from pathlib import Path
from beaky.config import Config from beaky.config import Config
@@ -10,17 +11,40 @@ class Screenshotter:
def capture_tickets(self, links: list[Link]): def capture_tickets(self, links: list[Link]):
for link in links:
print("capturing link:", link)
target_path = Path(self.config.screenshotter.target_path) / f"{link.id}.png"
self.capture_ticket(link.url, target_path)
def capture_ticket(self, url, target_path, ticket_selector=".betslip-history-detail"):
with sync_playwright() as p: with sync_playwright() as p:
browser = p.chromium.launch(headless=True) browser = p.chromium.launch(headless=True)
page = browser.new_page() context = browser.new_context()
page.goto(url, wait_until="domcontentloaded")
page.wait_for_selector(ticket_selector) for link in links:
page.wait_for_load_state("networkidle") print("capturing link:", link)
page.locator(ticket_selector).screenshot(path=target_path) page = context.new_page()
target_path = Path(self.config.screenshotter.target_path) / f"{link.id}.png"
self.capture_ticket(page, link.url, target_path)
browser.close() browser.close()
def capture_ticket(self,page, url, target_path, ticket_selector=".betslip-history-detail__left-panel"):
page.goto(url)
page.wait_for_selector(ticket_selector, timeout=10000)
page.wait_for_timeout(1000)
page.evaluate(f"""
let el = document.querySelector('{ticket_selector}');
if (el) {{
// Roztáhneme samotný kontejner se zápasy
let wrapper = el.querySelector('.betslip-selections');
if (wrapper) {{
wrapper.style.setProperty('height', 'auto', 'important');
wrapper.style.setProperty('overflow', 'visible', 'important');
}}
// A teď projdeme všechny nadřazené prvky až k <body>
while (el && el !== document.body) {{
el.style.setProperty('height', 'auto', 'important');
el.style.setProperty('max-height', 'none', 'important');
el.style.setProperty('overflow', 'visible', 'important');
el = el.parentElement;
}}
}}
""")
page.locator(ticket_selector).screenshot(path=target_path)