Модуль:FetchData: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
||
Рядок 5: | Рядок 5: | ||
local player = frame.args.player | local player = frame.args.player | ||
local | -- Only one title now, as all seasons are on the same page | ||
local season_title = "Сезони" | |||
local headings = { "I", "II", "III", "IV", "V" } | |||
local heading = headings[tonumber(season)] | |||
mw.log(" | if not heading then | ||
mw.log("Error: Invalid season number provided.") | |||
return "Invalid season number" | |||
end | |||
local title = mw.title.makeTitle(0, season_title) | local title = mw.title.makeTitle(0, season_title) | ||
Рядок 20: | Рядок 19: | ||
if not content then | if not content then | ||
mw.log("Error: Content not found for the | mw.log("Error: Content not found for the 'Сезони' page.") | ||
return "Season page not found" | return "Season page not found" | ||
end | end | ||
-- Matching the specific section for the season | |||
local pattern = "== " .. heading .. " ==" .. ".-{| class=\"wikitable sortable\"(.-)|}" | |||
local rating_section = mw.ustring.match(content, pattern) | |||
if not rating_section then | if not rating_section then | ||
mw.log("Error: Rating section not found | mw.log("Error: Rating section for season " .. heading .. " not found.") | ||
return "Rating section not found" | return "Rating section not found" | ||
end | end | ||
-- Extracting player ranking | |||
local rank_pattern = "|%s*%[%[" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "|[^%]]+%]%]%s*|%s*(%d+)%s*|" | |||
local | local direct_rank_pattern = "|%s*" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "%s*|%s*(%d+)%s*|" | ||
local | local rank = mw.ustring.match(rating_section, rank_pattern) or mw.ustring.match(rating_section, direct_rank_pattern) | ||
local rank = mw.ustring.match(rating_section, | |||
if not rank then | if not rank then | ||
mw.log("Error: Player not found in season rankings | mw.log("Error: Player '" .. player .. "' not found in season " .. heading .. " rankings.") | ||
return "Player not found in season rankings" | return "Player not found in season rankings" | ||
end | end | ||
return rank | return rank | ||
end | end | ||
return p | return p |
Версія за 15:19, 17 квітня 2024
Документацію для цього модуля можна створити у Модуль:FetchData/документація
local p = {} function p.season_result(frame) local season = frame.args.season local player = frame.args.player -- Only one title now, as all seasons are on the same page local season_title = "Сезони" local headings = { "I", "II", "III", "IV", "V" } local heading = headings[tonumber(season)] if not heading then mw.log("Error: Invalid season number provided.") return "Invalid season number" end local title = mw.title.makeTitle(0, season_title) local content = title:getContent() if not content then mw.log("Error: Content not found for the 'Сезони' page.") return "Season page not found" end -- Matching the specific section for the season local pattern = "== " .. heading .. " ==" .. ".-{| class=\"wikitable sortable\"(.-)|}" local rating_section = mw.ustring.match(content, pattern) if not rating_section then mw.log("Error: Rating section for season " .. heading .. " not found.") return "Rating section not found" end -- Extracting player ranking local rank_pattern = "|%s*%[%[" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "|[^%]]+%]%]%s*|%s*(%d+)%s*|" local direct_rank_pattern = "|%s*" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "%s*|%s*(%d+)%s*|" local rank = mw.ustring.match(rating_section, rank_pattern) or mw.ustring.match(rating_section, direct_rank_pattern) if not rank then mw.log("Error: Player '" .. player .. "' not found in season " .. heading .. " rankings.") return "Player not found in season rankings" end return rank end return p