Модуль:FetchData: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 19: | Рядок 19: | ||
if not content then | if not content then | ||
return "Season page not found" | return "Season page not found" | ||
end | |||
-- Extract the "Рейтинг" section | |||
local rating_section = content:match("== Рейтинг ==.-{|") | |||
if not rating_section then | |||
return "Rating section not found" | |||
end | end | ||
-- Lua patterns to match the player's data directly or linked | -- Lua patterns to match the player's data directly or linked | ||
local pattern = " | local pattern = "|%s*%[%[" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "|[^%]]+%]%]%s*|%s*(%d+)%s*|" | ||
local direct_pattern = " | local direct_pattern = "|%s*" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "%s*|%s*(%d+)%s*|" | ||
local rank = | local rank = rating_section:match(pattern) or rating_section:match(direct_pattern) | ||
if not rank then | if not rank then | ||
Версія за 14:52, 17 квітня 2024
Документацію для цього модуля можна створити у Модуль:FetchData/документація
local p = {}
function p.season_result(frame)
local season = frame.args.season
local player = frame.args.player
-- Determine the page title dynamically based on the season argument
local season_titles = {
"Перший_сезон", "Другий_сезон", "Третій_сезон",
"Четвертий_сезон", "П'ятий_сезон"
}
local season_title = season_titles[tonumber(season)]
if not season_title then
return "Invalid season number"
end
local title = mw.title.makeTitle(0, season_title)
local content = title:getContent()
if not content then
return "Season page not found"
end
-- Extract the "Рейтинг" section
local rating_section = content:match("== Рейтинг ==.-{|")
if not rating_section then
return "Rating section not found"
end
-- Lua patterns to match the player's data directly or linked
local pattern = "|%s*%[%[" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "|[^%]]+%]%]%s*|%s*(%d+)%s*|"
local direct_pattern = "|%s*" .. mw.ustring.gsub(player, "([%(%)%.%-%+])", "%%%1") .. "%s*|%s*(%d+)%s*|"
local rank = rating_section:match(pattern) or rating_section:match(direct_pattern)
if not rank then
return "Player not found in season rankings"
end
return rank
end
return p