From 0082ecc9f4894614712efcea771c6c7cad9055bb Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 11:47:10 -0500 Subject: [PATCH] refactor(timeouts): make `BROWSER_SUBMIT_NAV_TIMEOUT` a per-platform defaultdict --- scrapers/atcoder.py | 3 ++- scrapers/codeforces.py | 2 +- scrapers/timeouts.py | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scrapers/atcoder.py b/scrapers/atcoder.py index 61e4213..2e966b2 100644 --- a/scrapers/atcoder.py +++ b/scrapers/atcoder.py @@ -33,6 +33,7 @@ from .timeouts import ( BROWSER_NAV_TIMEOUT, BROWSER_SESSION_TIMEOUT, BROWSER_SETTLE_DELAY, + BROWSER_SUBMIT_NAV_TIMEOUT, BROWSER_TURNSTILE_POLL, HTTP_TIMEOUT, ) @@ -361,7 +362,7 @@ def _submit_headless( page.wait_for_timeout(BROWSER_SETTLE_DELAY) page.locator('button[type="submit"]').click() page.wait_for_url( - lambda url: "/submissions/me" in url, timeout=BROWSER_NAV_TIMEOUT + lambda url: "/submissions/me" in url, timeout=BROWSER_SUBMIT_NAV_TIMEOUT["atcoder"] ) except Exception as e: submit_error = str(e) diff --git a/scrapers/codeforces.py b/scrapers/codeforces.py index 2335da7..5ac615a 100644 --- a/scrapers/codeforces.py +++ b/scrapers/codeforces.py @@ -397,7 +397,7 @@ def _submit_headless( try: page.wait_for_url( lambda url: "/my" in url or "/status" in url, - timeout=BROWSER_SUBMIT_NAV_TIMEOUT, + timeout=BROWSER_SUBMIT_NAV_TIMEOUT["codeforces"], ) except Exception: err_el = page.query_selector("span.error") diff --git a/scrapers/timeouts.py b/scrapers/timeouts.py index 8a002a2..3dd6620 100644 --- a/scrapers/timeouts.py +++ b/scrapers/timeouts.py @@ -1,8 +1,11 @@ +from collections import defaultdict + HTTP_TIMEOUT = 15.0 BROWSER_SESSION_TIMEOUT = 15000 BROWSER_NAV_TIMEOUT = 10000 -BROWSER_SUBMIT_NAV_TIMEOUT = BROWSER_NAV_TIMEOUT * 2 +BROWSER_SUBMIT_NAV_TIMEOUT: defaultdict[str, int] = defaultdict(lambda: BROWSER_NAV_TIMEOUT) +BROWSER_SUBMIT_NAV_TIMEOUT["codeforces"] = BROWSER_NAV_TIMEOUT * 2 BROWSER_TURNSTILE_POLL = 5000 BROWSER_ELEMENT_WAIT = 10000 BROWSER_SETTLE_DELAY = 500