From d4df57bd05cd315ff54c73412bfdaff0d8784fd9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 5 Oct 2025 20:55:43 -0400 Subject: [PATCH] fix(scrapers): cses interactive problems --- lua/cp/commands/init.lua | 4 +--- lua/cp/setup.lua | 15 +++------------ scrapers/cses.py | 15 ++++++++++----- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lua/cp/commands/init.lua b/lua/cp/commands/init.lua index ae07889..9583204 100644 --- a/lua/cp/commands/init.lua +++ b/lua/cp/commands/init.lua @@ -153,9 +153,7 @@ function M.handle_command(opts) cache_commands.handle_cache_command(cmd) elseif cmd.type == 'contest_setup' then local setup = require('cp.setup') - if setup.set_platform(cmd.platform) then - setup.setup_contest(cmd.platform, cmd.contest, nil) - end + setup.setup_contest(cmd.platform, cmd.contest, nil) return end end diff --git a/lua/cp/setup.lua b/lua/cp/setup.lua index 3406c27..486aad9 100644 --- a/lua/cp/setup.lua +++ b/lua/cp/setup.lua @@ -7,16 +7,6 @@ local scraper = require('cp.scraper') local state = require('cp.state') local constants = require('cp.constants') -local platforms = constants.PLATFORMS - -function M.set_platform(platform) - if not vim.tbl_contains(platforms, platform) then - logger.log(("Unknown platform '%s'"):format(platform), vim.log.levels.ERROR) - return false - end - state.set_platform(platform) - return true -end ---@class TestCaseLite ---@field input string @@ -35,9 +25,10 @@ end ---@param platform string ---@param contest_id string ----@param problem_id string|nil ----@param language? string|nil +---@param problem_id? string +---@param language? string function M.setup_contest(platform, contest_id, problem_id, language) + state.set_platform(platform) state.set_contest_id(contest_id) cache.load() diff --git a/scrapers/cses.py b/scrapers/cses.py index 0ef9778..ea8f57a 100644 --- a/scrapers/cses.py +++ b/scrapers/cses.py @@ -132,12 +132,17 @@ def parse_category_problems(category_id: str, html: str) -> list[ProblemSummary] return [] -def parse_limits(html: str) -> tuple[int, int]: +def _extract_problem_info(html: str) -> tuple[int, int, bool]: tm = TIME_RE.search(html) mm = MEM_RE.search(html) t = int(round(float(tm.group(1)) * 1000)) if tm else 0 m = int(mm.group(1)) if mm else 0 - return t, m + md = MD_BLOCK_RE.search(html) + interactive = False + if md: + body = md.group(1) + interactive = "This is an interactive problem." in body + return t, m, interactive def parse_title(html: str) -> str: @@ -220,10 +225,10 @@ class CSESScraper(BaseScraper): try: html = await fetch_text(client, task_path(pid)) tests = parse_tests(html) - timeout_ms, memory_mb = parse_limits(html) + timeout_ms, memory_mb, interactive = _extract_problem_info(html) except Exception: tests = [] - timeout_ms, memory_mb = 0, 0 + timeout_ms, memory_mb, interactive = 0, 0, False return { "problem_id": pid, "tests": [ @@ -231,7 +236,7 @@ class CSESScraper(BaseScraper): ], "timeout_ms": timeout_ms, "memory_mb": memory_mb, - "interactive": False, + "interactive": interactive, } tasks = [run_one(p.id) for p in problems]