From d1b946934257901f1a87fe13da7f6720843be6cc Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sun, 14 Sep 2025 20:07:08 -0500 Subject: [PATCH] fix(scraper): multi-letter codeforces problems --- lua/cp/scrape.lua | 20 ++++++++++++++++++++ scrapers/codeforces.py | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lua/cp/scrape.lua b/lua/cp/scrape.lua index 09ba5c2..82e2e4f 100644 --- a/lua/cp/scrape.lua +++ b/lua/cp/scrape.lua @@ -11,6 +11,11 @@ local function ensure_io_directory() vim.fn.mkdir("io", "p") end +local function check_internet_connectivity() + local result = vim.system({ "ping", "-c", "1", "-W", "3", "8.8.8.8" }, { text = true }):wait() + return result.code == 0 +end + local function setup_python_env() local plugin_path = get_plugin_path() local venv_dir = plugin_path .. "/.venv" @@ -50,6 +55,13 @@ function M.scrape_contest_metadata(platform, contest_id) } end + if not check_internet_connectivity() then + return { + success = false, + error = "No internet connection available", + } + end + if not setup_python_env() then return { success = false, @@ -119,6 +131,14 @@ function M.scrape_problem(ctx) } end + if not check_internet_connectivity() then + return { + success = false, + problem_id = ctx.problem_name, + error = "No internet connection available", + } + end + if not setup_python_env() then return { success = false, diff --git a/scrapers/codeforces.py b/scrapers/codeforces.py index 73be5a4..f2d97fa 100644 --- a/scrapers/codeforces.py +++ b/scrapers/codeforces.py @@ -80,7 +80,7 @@ def scrape_contest_problems(contest_id: str) -> list[dict[str, str]]: problem_letter: str = href.split("/")[-1].lower() problem_name: str = link.get_text(strip=True) - if problem_letter and problem_name and len(problem_letter) == 1: + if problem_letter and problem_name: problems.append({"id": problem_letter, "name": problem_name}) problems.sort(key=lambda x: x["id"])