From f17eb854070d73573b5f5a8e57dfff146d149388 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 15:09:49 -0500 Subject: [PATCH] refactor(atcoder): replace custom `main_async` with `run_cli()` Problem: `atcoder.py` had a hand-rolled `main_async`/`main` dispatch that duplicated `BaseScraper._run_cli_async` and missed the new `login` subcommand. Solution: delete the duplicate dispatch and use `AtcoderScraper().run_cli()` like every other scraper. Remove now-unused imports (`sys`, `get_language_id`, `CombinedTest`, `TestsResult`). --- scrapers/atcoder.py | 95 +-------------------------------------------- 1 file changed, 1 insertion(+), 94 deletions(-) diff --git a/scrapers/atcoder.py b/scrapers/atcoder.py index db028d0..966940a 100644 --- a/scrapers/atcoder.py +++ b/scrapers/atcoder.py @@ -5,7 +5,6 @@ import json import os import re import subprocess -import sys import time from pathlib import Path from typing import Any @@ -18,9 +17,7 @@ from requests.adapters import HTTPAdapter from urllib3.util.retry import Retry from .base import BaseScraper, extract_precision -from .language_ids import get_language_id from .models import ( - CombinedTest, ContestListResult, ContestSummary, LoginResult, @@ -28,7 +25,6 @@ from .models import ( ProblemSummary, SubmitResult, TestCase, - TestsResult, ) from .timeouts import ( BROWSER_ELEMENT_WAIT, @@ -681,94 +677,5 @@ class AtcoderScraper(BaseScraper): return await asyncio.to_thread(_login_headless, credentials) -async def main_async() -> int: - if len(sys.argv) < 2: - result = MetadataResult( - success=False, - error="Usage: atcoder.py metadata OR atcoder.py tests OR atcoder.py contests", - url="", - ) - print(result.model_dump_json()) - return 1 - - mode: str = sys.argv[1] - scraper = AtcoderScraper() - - if mode == "metadata": - if len(sys.argv) != 3: - result = MetadataResult( - success=False, - error="Usage: atcoder.py metadata ", - url="", - ) - print(result.model_dump_json()) - return 1 - contest_id = sys.argv[2] - result = await scraper.scrape_contest_metadata(contest_id) - print(result.model_dump_json()) - return 0 if result.success else 1 - - if mode == "tests": - if len(sys.argv) != 3: - tests_result = TestsResult( - success=False, - error="Usage: atcoder.py tests ", - problem_id="", - combined=CombinedTest(input="", expected=""), - tests=[], - timeout_ms=0, - memory_mb=0, - ) - print(tests_result.model_dump_json()) - return 1 - contest_id = sys.argv[2] - await scraper.stream_tests_for_category_async(contest_id) - return 0 - - if mode == "contests": - if len(sys.argv) != 2: - contest_result = ContestListResult( - success=False, error="Usage: atcoder.py contests" - ) - print(contest_result.model_dump_json()) - return 1 - contest_result = await scraper.scrape_contest_list() - print(contest_result.model_dump_json()) - return 0 if contest_result.success else 1 - - if mode == "submit": - if len(sys.argv) != 6: - print( - SubmitResult( - success=False, - error="Usage: atcoder.py submit ", - ).model_dump_json() - ) - return 1 - creds_raw = os.environ.get("CP_CREDENTIALS", "{}") - try: - credentials = json.loads(creds_raw) - except json.JSONDecodeError: - credentials = {} - language_id = get_language_id("atcoder", sys.argv[4]) or sys.argv[4] - submit_result = await scraper.submit( - sys.argv[2], sys.argv[3], sys.argv[5], language_id, credentials - ) - print(submit_result.model_dump_json()) - return 0 if submit_result.success else 1 - - result = MetadataResult( - success=False, - error="Unknown mode. Use 'metadata ', 'tests ', 'contests', or 'submit '", - url="", - ) - print(result.model_dump_json()) - return 1 - - -def main() -> None: - sys.exit(asyncio.run(main_async())) - - if __name__ == "__main__": - main() + AtcoderScraper().run_cli()