ci: format

This commit is contained in:
Barrett Ruth 2026-03-05 01:39:59 -05:00
parent 2cdde85d36
commit 1afe41103f
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
4 changed files with 17 additions and 25 deletions

View file

@ -338,7 +338,9 @@ def _submit_headless(
page.fill('input[name="username"]', credentials.get("username", "")) page.fill('input[name="username"]', credentials.get("username", ""))
page.fill('input[name="password"]', credentials.get("password", "")) page.fill('input[name="password"]', credentials.get("password", ""))
page.click("#submit") page.click("#submit")
page.wait_for_url(lambda url: "/login" not in url, timeout=BROWSER_NAV_TIMEOUT) page.wait_for_url(
lambda url: "/login" not in url, timeout=BROWSER_NAV_TIMEOUT
)
except Exception as e: except Exception as e:
login_error = str(e) login_error = str(e)
@ -365,7 +367,9 @@ def _submit_headless(
finally: finally:
os.unlink(tmp_path) os.unlink(tmp_path)
page.locator('button[type="submit"]').click() page.locator('button[type="submit"]').click()
page.wait_for_url(lambda url: "/submissions/me" in url, timeout=BROWSER_NAV_TIMEOUT) page.wait_for_url(
lambda url: "/submissions/me" in url, timeout=BROWSER_NAV_TIMEOUT
)
except Exception as e: except Exception as e:
submit_error = str(e) submit_error = str(e)

View file

@ -328,9 +328,7 @@ def _submit_headless(
_ensure_browser() _ensure_browser()
cookie_cache = ( cookie_cache = Path.home() / ".cache" / "cp-nvim" / "codeforces-cookies.json"
Path.home() / ".cache" / "cp-nvim" / "codeforces-cookies.json"
)
cookie_cache.parent.mkdir(parents=True, exist_ok=True) cookie_cache.parent.mkdir(parents=True, exist_ok=True)
saved_cookies: list[dict[str, Any]] = [] saved_cookies: list[dict[str, Any]] = []
if cookie_cache.exists(): if cookie_cache.exists():
@ -372,9 +370,7 @@ def _submit_headless(
'input[name="password"]', 'input[name="password"]',
credentials.get("password", ""), credentials.get("password", ""),
) )
page.locator( page.locator('#enterForm input[type="submit"]').click()
'#enterForm input[type="submit"]'
).click()
page.wait_for_url( page.wait_for_url(
lambda url: "/enter" not in url, timeout=BROWSER_NAV_TIMEOUT lambda url: "/enter" not in url, timeout=BROWSER_NAV_TIMEOUT
) )
@ -394,24 +390,20 @@ def _submit_headless(
'select[name="submittedProblemIndex"]', 'select[name="submittedProblemIndex"]',
problem_id.upper(), problem_id.upper(),
) )
page.select_option( page.select_option('select[name="programTypeId"]', language_id)
'select[name="programTypeId"]', language_id
)
with tempfile.NamedTemporaryFile( with tempfile.NamedTemporaryFile(
mode="w", suffix=".cpp", delete=False, prefix="cf_" mode="w", suffix=".cpp", delete=False, prefix="cf_"
) as tf: ) as tf:
tf.write(source_code) tf.write(source_code)
tmp_path = tf.name tmp_path = tf.name
try: try:
page.set_input_files( page.set_input_files('input[name="sourceFile"]', tmp_path)
'input[name="sourceFile"]', tmp_path
)
page.wait_for_timeout(BROWSER_SETTLE_DELAY) page.wait_for_timeout(BROWSER_SETTLE_DELAY)
except Exception: except Exception:
page.fill('textarea[name="source"]', source_code) page.fill('textarea[name="source"]', source_code)
finally: finally:
os.unlink(tmp_path) os.unlink(tmp_path)
page.locator('form.submit-form input.submit').click() page.locator("form.submit-form input.submit").click()
page.wait_for_url( page.wait_for_url(
lambda url: "/my" in url or "/status" in url, lambda url: "/my" in url or "/status" in url,
timeout=BROWSER_NAV_TIMEOUT, timeout=BROWSER_NAV_TIMEOUT,
@ -435,17 +427,13 @@ def _submit_headless(
try: try:
browser_cookies = session.context.cookies() browser_cookies = session.context.cookies()
if any( if any(c["name"] == "JSESSIONID" for c in browser_cookies):
c["name"] == "JSESSIONID" for c in browser_cookies
):
cookie_cache.write_text(json.dumps(browser_cookies)) cookie_cache.write_text(json.dumps(browser_cookies))
except Exception: except Exception:
pass pass
if login_error: if login_error:
return SubmitResult( return SubmitResult(success=False, error=f"Login failed: {login_error}")
success=False, error=f"Login failed: {login_error}"
)
if submit_error: if submit_error:
return SubmitResult(success=False, error=submit_error) return SubmitResult(success=False, error=submit_error)

View file

@ -342,9 +342,7 @@ class CSESScraper(BaseScraper):
return None return None
return token return token
async def _check_token( async def _check_token(self, client: httpx.AsyncClient, token: str) -> bool:
self, client: httpx.AsyncClient, token: str
) -> bool:
try: try:
r = await client.get( r = await client.get(
f"{API_URL}/login", f"{API_URL}/login",

View file

@ -58,7 +58,9 @@ RESULTS_PAGE_RE = re.compile(
async def _fetch_text(client: httpx.AsyncClient, url: str) -> str: async def _fetch_text(client: httpx.AsyncClient, url: str) -> str:
r = await client.get(url, headers=HEADERS, timeout=HTTP_TIMEOUT, follow_redirects=True) r = await client.get(
url, headers=HEADERS, timeout=HTTP_TIMEOUT, follow_redirects=True
)
r.raise_for_status() r.raise_for_status()
return r.text return r.text