fix(codechef): fix
This commit is contained in:
parent
1d8f01a2a7
commit
904bd9c18c
2 changed files with 35 additions and 15 deletions
|
|
@ -81,7 +81,7 @@ def _login_headless_codechef(credentials: dict[str, str]) -> LoginResult:
|
||||||
try:
|
try:
|
||||||
page.locator('input[name="name"]').fill(credentials.get("username", ""))
|
page.locator('input[name="name"]').fill(credentials.get("username", ""))
|
||||||
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
|
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
|
||||||
page.locator('input.cc-login-btn').click()
|
page.locator("input.cc-login-btn").click()
|
||||||
try:
|
try:
|
||||||
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
|
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -163,7 +163,7 @@ def _submit_headless_codechef(
|
||||||
try:
|
try:
|
||||||
page.locator('input[name="name"]').fill(credentials.get("username", ""))
|
page.locator('input[name="name"]').fill(credentials.get("username", ""))
|
||||||
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
|
page.locator('input[name="pass"]').fill(credentials.get("password", ""))
|
||||||
page.locator('input.cc-login-btn').click()
|
page.locator("input.cc-login-btn").click()
|
||||||
try:
|
try:
|
||||||
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
|
page.wait_for_url(lambda url: "/login" not in url, timeout=3000)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -185,8 +185,8 @@ def _submit_headless_codechef(
|
||||||
page.locator(f'[role="option"][data-value="{language_id}"]').click()
|
page.locator(f'[role="option"][data-value="{language_id}"]').click()
|
||||||
page.wait_for_timeout(2000)
|
page.wait_for_timeout(2000)
|
||||||
|
|
||||||
page.locator('.ace_editor').click()
|
page.locator(".ace_editor").click()
|
||||||
page.keyboard.press('Control+a')
|
page.keyboard.press("Control+a")
|
||||||
page.wait_for_timeout(200)
|
page.wait_for_timeout(200)
|
||||||
page.evaluate(
|
page.evaluate(
|
||||||
"""(code) => {
|
"""(code) => {
|
||||||
|
|
@ -205,7 +205,7 @@ def _submit_headless_codechef(
|
||||||
"() => document.getElementById('submit_btn').scrollIntoView({block:'center'})"
|
"() => document.getElementById('submit_btn').scrollIntoView({block:'center'})"
|
||||||
)
|
)
|
||||||
page.wait_for_timeout(200)
|
page.wait_for_timeout(200)
|
||||||
page.locator('#submit_btn').dispatch_event('click')
|
page.locator("#submit_btn").dispatch_event("click")
|
||||||
page.wait_for_timeout(3000)
|
page.wait_for_timeout(3000)
|
||||||
|
|
||||||
dialog_text = page.evaluate("""() => {
|
dialog_text = page.evaluate("""() => {
|
||||||
|
|
@ -342,7 +342,11 @@ class CodeChefScraper(BaseScraper):
|
||||||
async def fetch_past_page(offset: int) -> list[dict[str, Any]]:
|
async def fetch_past_page(offset: int) -> list[dict[str, Any]]:
|
||||||
r = await client.get(
|
r = await client.get(
|
||||||
BASE_URL + API_CONTESTS_PAST,
|
BASE_URL + API_CONTESTS_PAST,
|
||||||
params={"sort_by": "START", "sorting_order": "desc", "offset": offset},
|
params={
|
||||||
|
"sort_by": "START",
|
||||||
|
"sorting_order": "desc",
|
||||||
|
"offset": offset,
|
||||||
|
},
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
timeout=HTTP_TIMEOUT,
|
timeout=HTTP_TIMEOUT,
|
||||||
)
|
)
|
||||||
|
|
@ -353,7 +357,9 @@ class CodeChefScraper(BaseScraper):
|
||||||
offset = 0
|
offset = 0
|
||||||
while True:
|
while True:
|
||||||
page = await fetch_past_page(offset)
|
page = await fetch_past_page(offset)
|
||||||
past.extend(c for c in page if re.match(r"^START\d+", c.get("contest_code", "")))
|
past.extend(
|
||||||
|
c for c in page if re.match(r"^START\d+", c.get("contest_code", ""))
|
||||||
|
)
|
||||||
if len(page) < 20:
|
if len(page) < 20:
|
||||||
break
|
break
|
||||||
offset += 20
|
offset += 20
|
||||||
|
|
@ -382,7 +388,9 @@ class CodeChefScraper(BaseScraper):
|
||||||
base_name = re.sub(r"\s*\(.*?\)\s*$", "", name).strip()
|
base_name = re.sub(r"\s*\(.*?\)\s*$", "", name).strip()
|
||||||
try:
|
try:
|
||||||
async with sem:
|
async with sem:
|
||||||
detail = await fetch_json(client, API_CONTEST.format(contest_id=code))
|
detail = await fetch_json(
|
||||||
|
client, API_CONTEST.format(contest_id=code)
|
||||||
|
)
|
||||||
children = detail.get("child_contests")
|
children = detail.get("child_contests")
|
||||||
if children and isinstance(children, dict):
|
if children and isinstance(children, dict):
|
||||||
divs: list[ContestSummary] = []
|
divs: list[ContestSummary] = []
|
||||||
|
|
@ -391,17 +399,28 @@ class CodeChefScraper(BaseScraper):
|
||||||
if not child:
|
if not child:
|
||||||
continue
|
continue
|
||||||
child_code = child.get("contest_code")
|
child_code = child.get("contest_code")
|
||||||
div_num = child.get("div", {}).get("div_number", div_key[-1])
|
div_num = child.get("div", {}).get(
|
||||||
|
"div_number", div_key[-1]
|
||||||
|
)
|
||||||
if child_code:
|
if child_code:
|
||||||
display = f"{base_name} (Div. {div_num})"
|
display = f"{base_name} (Div. {div_num})"
|
||||||
divs.append(ContestSummary(
|
divs.append(
|
||||||
id=child_code, name=display, display_name=display, start_time=start_time
|
ContestSummary(
|
||||||
))
|
id=child_code,
|
||||||
|
name=display,
|
||||||
|
display_name=display,
|
||||||
|
start_time=start_time,
|
||||||
|
)
|
||||||
|
)
|
||||||
if divs:
|
if divs:
|
||||||
return divs
|
return divs
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
return [ContestSummary(id=code, name=name, display_name=name, start_time=start_time)]
|
return [
|
||||||
|
ContestSummary(
|
||||||
|
id=code, name=name, display_name=name, start_time=start_time
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
results = await asyncio.gather(*[expand(c) for c in raw])
|
results = await asyncio.gather(*[expand(c) for c in raw])
|
||||||
|
|
||||||
|
|
@ -434,7 +453,9 @@ class CodeChefScraper(BaseScraper):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
all_problems = contest_data.get("problems", {})
|
all_problems = contest_data.get("problems", {})
|
||||||
if not all_problems and isinstance(contest_data.get("child_contests"), dict):
|
if not all_problems and isinstance(
|
||||||
|
contest_data.get("child_contests"), dict
|
||||||
|
):
|
||||||
for div in ("div_4", "div_3", "div_2", "div_1"):
|
for div in ("div_4", "div_3", "div_2", "div_1"):
|
||||||
child = contest_data["child_contests"].get(div, {})
|
child = contest_data["child_contests"].get(div, {})
|
||||||
child_code = child.get("contest_code")
|
child_code = child.get("contest_code")
|
||||||
|
|
|
||||||
|
|
@ -12,4 +12,3 @@ BROWSER_SUBMIT_NAV_TIMEOUT["codeforces"] = BROWSER_NAV_TIMEOUT * 2
|
||||||
BROWSER_TURNSTILE_POLL = 5000
|
BROWSER_TURNSTILE_POLL = 5000
|
||||||
BROWSER_ELEMENT_WAIT = 10000
|
BROWSER_ELEMENT_WAIT = 10000
|
||||||
BROWSER_SETTLE_DELAY = 500
|
BROWSER_SETTLE_DELAY = 500
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue