Модуль:FetchData: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
Рядок 5: | Рядок 5: | ||
local player = frame.args.player | local player = frame.args.player | ||
local season_titles = { | local season_titles = { | ||
"Перший_сезон", "Другий_сезон", "Третій_сезон", | "Перший_сезон", "Другий_сезон", "Третій_сезон", | ||
"Четвертий_сезон", "П'ятий_сезон" | "Четвертий_сезон", "П'ятий_сезон" | ||
} | } | ||
-- Log the input variables for debugging | |||
mw.log("Season index: ", season) | |||
mw.log("Player name: ", player) | |||
local season_title = season_titles[tonumber(season)] | local season_title = season_titles[tonumber(season)] | ||
if not season_title then | if not season_title then | ||
mw.log("Error: Invalid season number provided.") | |||
return "Invalid season number" | return "Invalid season number" | ||
end | end | ||
mw.log("Season page title: ", season_title) | |||
local title = mw.title.makeTitle(0, season_title) | local title = mw.title.makeTitle(0, season_title) | ||
local content = title:getContent() | local content = title:getContent() | ||
if not content then | if not content then | ||
mw.log("Error: Content not found for the season page.") | |||
return "Season page not found" | return "Season page not found" | ||
end | end | ||
local rating_section = mw.ustring.match(content, "== Рейтинг ==.-{| class=\"wikitable sortable\"(.-)|}") | local rating_section = mw.ustring.match(content, "== Рейтинг ==.-{| class=\"wikitable sortable\"(.-)|}") | ||
if not rating_section then | if not rating_section then | ||
mw.log("Error: Rating section not found within the page content.") | |||
return "Rating section not found" | return "Rating section not found" | ||
end | end | ||
Рядок 31: | Рядок 38: | ||
local direct_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 = mw.ustring.match(rating_section, pattern) or mw.ustring.match(rating_section, direct_pattern) | local rank = mw.ustring.match(rating_section, pattern) or mw.ustring.match(rating_section, direct_pattern) | ||
if not rank then | if not rank then | ||
mw.log("Error: Player not found in season rankings or regex failed.") | |||
return "Player not found in season rankings" | return "Player not found in season rankings" | ||
end | end | ||
mw.log("Player rank found: ", rank) | |||
return rank | return rank | ||
end | end | ||
return p | return p |
Версія за 15:07, 17 квітня 2024
Документацію для цього модуля можна створити у Модуль:FetchData/документація
local p = {} function p.season_result(frame) local season = frame.args.season local player = frame.args.player local season_titles = { "Перший_сезон", "Другий_сезон", "Третій_сезон", "Четвертий_сезон", "П'ятий_сезон" } -- Log the input variables for debugging mw.log("Season index: ", season) mw.log("Player name: ", player) local season_title = season_titles[tonumber(season)] if not season_title then mw.log("Error: Invalid season number provided.") return "Invalid season number" end mw.log("Season page title: ", season_title) local title = mw.title.makeTitle(0, season_title) local content = title:getContent() if not content then mw.log("Error: Content not found for the season page.") return "Season page not found" end local rating_section = mw.ustring.match(content, "== Рейтинг ==.-{| class=\"wikitable sortable\"(.-)|}") if not rating_section then mw.log("Error: Rating section not found within the page content.") return "Rating section not found" end 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 = mw.ustring.match(rating_section, pattern) or mw.ustring.match(rating_section, direct_pattern) if not rank then mw.log("Error: Player not found in season rankings or regex failed.") return "Player not found in season rankings" end mw.log("Player rank found: ", rank) return rank end return p