fix: "cache" scrapes

This commit is contained in:
Barrett Ruth 2025-09-12 23:06:26 -05:00
parent 20712dd427
commit 8201a11a42
2 changed files with 27 additions and 14 deletions

View file

@ -249,22 +249,17 @@ function M.handle_command(opts)
debug_problem()
elseif cmd == "diff" then
diff_problem()
else
local similar_contests = vim.tbl_filter(function(contest)
return contest:find(cmd:sub(1, 3), 1, true) == 1
end, competition_types)
if #similar_contests > 0 then
log(
("unknown contest type '%s'. Did you mean: %s"):format(cmd, table.concat(similar_contests, ", ")),
vim.log.levels.ERROR
)
elseif vim.g.cp_contest and not vim.tbl_contains(competition_types, cmd) then
if (vim.g.cp_contest == "atcoder" or vim.g.cp_contest == "codeforces") and args[2] then
setup_problem(cmd, args[2])
else
log(
("unknown contest type '%s'. Available: [%s]"):format(cmd, table.concat(competition_types, ", ")),
vim.log.levels.ERROR
)
setup_problem(cmd)
end
else
log(
("unknown contest type '%s'. Available: [%s]"):format(cmd, table.concat(competition_types, ", ")),
vim.log.levels.ERROR
)
end
end

View file

@ -41,6 +41,24 @@ end
function M.scrape_problem(contest, problem_id, problem_letter)
ensure_io_directory()
local full_problem_id = problem_id:lower()
if contest == "atcoder" or contest == "codeforces" then
if problem_letter then
full_problem_id = full_problem_id .. problem_letter:upper()
end
end
local input_file = "io/" .. full_problem_id .. ".in"
local expected_file = "io/" .. full_problem_id .. ".expected"
if vim.fn.filereadable(input_file) == 1 and vim.fn.filereadable(expected_file) == 1 then
return {
success = true,
problem_id = full_problem_id,
test_count = 1,
}
end
if not setup_python_env() then
return {
success = false,