fix(ci): more fixes
This commit is contained in:
parent
83514c453e
commit
89c1a3c683
3 changed files with 21 additions and 33 deletions
|
|
@ -266,43 +266,31 @@ class AtcoderScraper(BaseScraper):
|
||||||
return "atcoder"
|
return "atcoder"
|
||||||
|
|
||||||
async def scrape_contest_metadata(self, contest_id: str) -> MetadataResult:
|
async def scrape_contest_metadata(self, contest_id: str) -> MetadataResult:
|
||||||
async def impl(cid: str) -> MetadataResult:
|
try:
|
||||||
try:
|
rows = await asyncio.to_thread(_scrape_tasks_sync, contest_id)
|
||||||
rows = await asyncio.to_thread(_scrape_tasks_sync, cid)
|
|
||||||
except requests.HTTPError as e:
|
|
||||||
if e.response is not None and e.response.status_code == 404:
|
|
||||||
return self._create_metadata_error(
|
|
||||||
f"No problems found for contest {cid}", cid
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
|
|
||||||
problems = _to_problem_summaries(rows)
|
problems = _to_problem_summaries(rows)
|
||||||
if not problems:
|
if not problems:
|
||||||
return self._create_metadata_error(
|
return self._metadata_error(
|
||||||
f"No problems found for contest {cid}", cid
|
f"No problems found for contest {contest_id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return MetadataResult(
|
return MetadataResult(
|
||||||
success=True,
|
success=True,
|
||||||
error="",
|
error="",
|
||||||
contest_id=cid,
|
contest_id=contest_id,
|
||||||
problems=problems,
|
problems=problems,
|
||||||
url=f"https://atcoder.jp/contests/{contest_id}/tasks/{contest_id}_%s",
|
url=f"https://atcoder.jp/contests/{contest_id}/tasks/{contest_id}_%s",
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
return await self._safe_execute("metadata", impl, contest_id)
|
return self._metadata_error(str(e))
|
||||||
|
|
||||||
async def scrape_contest_list(self) -> ContestListResult:
|
async def scrape_contest_list(self) -> ContestListResult:
|
||||||
async def impl() -> ContestListResult:
|
try:
|
||||||
try:
|
contests = await _fetch_all_contests_async()
|
||||||
contests = await _fetch_all_contests_async()
|
|
||||||
except Exception as e:
|
|
||||||
return self._create_contests_error(str(e))
|
|
||||||
if not contests:
|
if not contests:
|
||||||
return self._create_contests_error("No contests found")
|
return self._contests_error("No contests found")
|
||||||
return ContestListResult(success=True, error="", contests=contests)
|
return ContestListResult(success=True, error="", contests=contests)
|
||||||
|
except Exception as e:
|
||||||
return await self._safe_execute("contests", impl)
|
return self._contests_error(str(e))
|
||||||
|
|
||||||
async def stream_tests_for_category_async(self, category_id: str) -> None:
|
async def stream_tests_for_category_async(self, category_id: str) -> None:
|
||||||
rows = await asyncio.to_thread(_scrape_tasks_sync, category_id)
|
rows = await asyncio.to_thread(_scrape_tasks_sync, category_id)
|
||||||
|
|
|
||||||
|
|
@ -86,14 +86,14 @@ def _extract_samples(block: Tag) -> tuple[list[TestCase], bool]:
|
||||||
if not st:
|
if not st:
|
||||||
return [], False
|
return [], False
|
||||||
|
|
||||||
input_pres: list[Tag] = [ # type: ignore[misc]
|
input_pres: list[Tag] = [
|
||||||
inp.find("pre") # type: ignore[misc]
|
inp.find("pre")
|
||||||
for inp in st.find_all("div", class_="input") # type: ignore[union-attr]
|
for inp in st.find_all("div", class_="input")
|
||||||
if isinstance(inp, Tag) and inp.find("pre")
|
if isinstance(inp, Tag) and inp.find("pre")
|
||||||
]
|
]
|
||||||
output_pres: list[Tag] = [
|
output_pres: list[Tag] = [
|
||||||
out.find("pre") # type: ignore[misc]
|
out.find("pre")
|
||||||
for out in st.find_all("div", class_="output") # type: ignore[union-attr]
|
for out in st.find_all("div", class_="output")
|
||||||
if isinstance(out, Tag) and out.find("pre")
|
if isinstance(out, Tag) and out.find("pre")
|
||||||
]
|
]
|
||||||
input_pres = [p for p in input_pres if isinstance(p, Tag)]
|
input_pres = [p for p in input_pres if isinstance(p, Tag)]
|
||||||
|
|
|
||||||
|
|
@ -245,16 +245,16 @@ def run_scraper_offline(fixture_text):
|
||||||
offline_fetches = _make_offline_fetches(scraper_name)
|
offline_fetches = _make_offline_fetches(scraper_name)
|
||||||
|
|
||||||
if scraper_name == "codeforces":
|
if scraper_name == "codeforces":
|
||||||
fetchers.Fetcher.get = offline_fetches["Fetcher.get"] # type: ignore[assignment]
|
fetchers.Fetcher.get = offline_fetches["Fetcher.get"]
|
||||||
requests.get = offline_fetches["requests.get"]
|
requests.get = offline_fetches["requests.get"]
|
||||||
elif scraper_name == "atcoder":
|
elif scraper_name == "atcoder":
|
||||||
ns._fetch = offline_fetches["_fetch"]
|
ns._fetch = offline_fetches["_fetch"]
|
||||||
ns._get_async = offline_fetches["_get_async"]
|
ns._get_async = offline_fetches["_get_async"]
|
||||||
elif scraper_name == "cses":
|
elif scraper_name == "cses":
|
||||||
httpx.AsyncClient.get = offline_fetches["__offline_fetch_text"] # type: ignore[assignment]
|
httpx.AsyncClient.get = offline_fetches["__offline_fetch_text"]
|
||||||
elif scraper_name == "codechef":
|
elif scraper_name == "codechef":
|
||||||
httpx.AsyncClient.get = offline_fetches["__offline_get_async"] # type: ignore[assignment]
|
httpx.AsyncClient.get = offline_fetches["__offline_get_async"]
|
||||||
fetchers.Fetcher.get = offline_fetches["Fetcher.get"] # type: ignore[assignment]
|
fetchers.Fetcher.get = offline_fetches["Fetcher.get"]
|
||||||
|
|
||||||
scraper_class = getattr(ns, scraper_classes[scraper_name])
|
scraper_class = getattr(ns, scraper_classes[scraper_name])
|
||||||
scraper = scraper_class()
|
scraper = scraper_class()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue