INNER CODE UNIT · Python

last_size

defiprime/defiprime1 · scripts/product_add.py:89

    last_size = -1
    while time.monotonic() < deadline:
        if raw.exists() and raw.stat().st_size > 0 and raw.stat().st_size == last_size:
            break
        last_size = raw.stat().st_size if raw.exists() else -1
        if process.poll() is not None and raw.exists():
            break
        time.sleep(1)
    process.kill()
    process.wait()
    if not raw.exists() or raw.stat().st_size == 0:
        raise RuntimeError(f"no screenshot produced within {timeout}s")


def capture_screenshot(url, path):
    with tempfile.TemporaryDirectory() as profile:
        raw = Path(profile) / "raw.png"
        command = [CHROME, "--headless=new", "--disable-gpu", "--hide-scrollbars", f"--user-agent={USER_AGENT}", f"--window-size={CAPTURE_SIZE[0]},{CAPTURE_SIZE[1]}", f"--screenshot={raw}", "--virtual-time-budget=8000", f"--user-data-dir={profile}/chrome", url]

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…