remove outdated vars

This commit is contained in:
Barrett Ruth 2025-09-13 23:52:36 -05:00
parent e66c57530e
commit 0bdf69621e
2 changed files with 22 additions and 22 deletions

View file

@ -3,15 +3,15 @@ local M = {}
local cache_file = vim.fn.stdpath("data") .. "/cp-contest-cache.json"
local cache_data = {}
local function get_expiry_date(contest_type)
if contest_type == "cses" then
local function get_expiry_date(platform)
if platform == "cses" then
return os.time() + (30 * 24 * 60 * 60)
end
return nil
end
local function is_cache_valid(contest_data, contest_type)
if contest_type ~= "cses" then
local function is_cache_valid(contest_data, platform)
if platform ~= "cses" then
return true
end
@ -49,40 +49,40 @@ function M.save()
vim.fn.writefile(vim.split(encoded, "\n"), cache_file)
end
function M.get_contest_data(contest_type, contest_id)
if not cache_data[contest_type] then
function M.get_contest_data(platform, contest_id)
if not cache_data[platform] then
return nil
end
local contest_data = cache_data[contest_type][contest_id]
local contest_data = cache_data[platform][contest_id]
if not contest_data then
return nil
end
if not is_cache_valid(contest_data, contest_type) then
if not is_cache_valid(contest_data, platform) then
return nil
end
return contest_data
end
function M.set_contest_data(contest_type, contest_id, problems)
if not cache_data[contest_type] then
cache_data[contest_type] = {}
function M.set_contest_data(platform, contest_id, problems)
if not cache_data[platform] then
cache_data[platform] = {}
end
cache_data[contest_type][contest_id] = {
cache_data[platform][contest_id] = {
problems = problems,
scraped_at = os.date("%Y-%m-%d"),
expires_at = get_expiry_date(contest_type),
expires_at = get_expiry_date(platform),
}
M.save()
end
function M.clear_contest_data(contest_type, contest_id)
if cache_data[contest_type] and cache_data[contest_type][contest_id] then
cache_data[contest_type][contest_id] = nil
function M.clear_contest_data(platform, contest_id)
if cache_data[platform] and cache_data[platform][contest_id] then
cache_data[platform][contest_id] = nil
M.save()
end
end

View file

@ -36,13 +36,13 @@ local function setup_python_env()
return true
end
---@param contest_type string
---@param platform string
---@param contest_id string
---@return {success: boolean, problems?: table[], error?: string}
function M.scrape_contest_metadata(contest_type, contest_id)
function M.scrape_contest_metadata(platform, contest_id)
cache.load()
local cached_data = cache.get_contest_data(contest_type, contest_id)
local cached_data = cache.get_contest_data(platform, contest_id)
if cached_data then
return {
success = true,
@ -58,7 +58,7 @@ function M.scrape_contest_metadata(contest_type, contest_id)
end
local plugin_path = get_plugin_path()
local scraper_path = plugin_path .. "/scrapers/" .. contest_type .. ".py"
local scraper_path = plugin_path .. "/scrapers/" .. platform .. ".py"
local args = { "uv", "run", scraper_path, "metadata", contest_id }
local result = vim.system(args, {
@ -87,13 +87,13 @@ function M.scrape_contest_metadata(contest_type, contest_id)
end
local problems_list
if contest_type == "cses" then
if platform == "cses" then
problems_list = data.categories and data.categories["CSES Problem Set"] or {}
else
problems_list = data.problems or {}
end
cache.set_contest_data(contest_type, contest_id, problems_list)
cache.set_contest_data(platform, contest_id, problems_list)
return {
success = true,
problems = problems_list,