(Створена сторінка: local p = {} function p.season_result(frame) local season = frame.args.season local player = frame.args.player local title = mw.title.makeTitle(0, "Перший_сезон") -- change based on season argument local content = title:getContent() -- Find the player's row and extract the place local pattern = "|%s*" .. player .. "%s*|%s*%d+%s*|" local start_pos, end_pos = string.find(content, pattern) if not start_pos then...)
 
Немає опису редагування
 
(Не показано 18 проміжних версій цього користувача)
Рядок 4: Рядок 4:
     local season = frame.args.season
     local season = frame.args.season
     local player = frame.args.player
     local player = frame.args.player
    local title = mw.title.makeTitle(0, "Перший_сезон") -- change based on season argument
    local content = title:getContent()


     -- Find the player's row and extract the place
     -- Updated list of seasons with new entries
     local pattern = "|%s*" .. player .. "%s*|%s*%d+%s*|"
    local season_titles = {
     local start_pos, end_pos = string.find(content, pattern)
        "Перший_сезон", "Другий_сезон", "Третій_сезон",
     if not start_pos then
        "Четвертий_сезон", "П'ятий_сезон", "Шостий_сезон",
         return "Data not found"
        "Сьомий_сезон", "Восьмий_сезон", "Дев'ятий_сезон"
    }
 
    mw.log("Season index: ", season)
    mw.log("Player name: ", player)
 
    local season_title = season_titles[tonumber(season)]
    mw.log("Season page title: ", season_title)
 
    if not season_title then
        return "??"
    end
 
    local title = mw.title.new(season_title)
    local content = title and title:getContent()
 
    if not content then
        mw.log("Error: Content not found for the season page.")
        return "??"
    end
 
    mw.log("Page content loaded, length: ", string.len(content))
    mw.log("Page content preview: ", mw.ustring.sub(content, 1, 500))
 
    -- Attempt to extract the "Рейтинг" section
    local rating_section = mw.ustring.match(content, "==%s*Рейтинг%s*==.-{|%s*class%s*=%s*\"wikitable sortable\"(.-)|}")
    if not rating_section then
        mw.log("Error: Rating section not found within the page content.")
        mw.log("Page content: ", mw.ustring.sub(content, 1, 1000)) -- Log more content for better debugging
        return "Rating section not found"
    end
 
    mw.log("Rating section extracted, length: ", string.len(rating_section))
    mw.log("Rating section preview: ", mw.ustring.sub(rating_section, 1, 500))
 
    -- Adjusted to fetch the player's position (column 1 "№") instead of points
     local pattern = "|%s*(%d+)%s*|%s*%[%[" .. mw.ustring.gsub(player, "([%(%)%.%-%+%[%]])", "%%%1") .. "%]%]"
    local direct_pattern = "|%s*(%d+)%s*|%s*" .. mw.ustring.gsub(player, "([%(%)%.%-%+%[%]])", "%%%1") .. "%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.")
        mw.log("Pattern used: ", pattern)
        mw.log("Direct pattern used: ", direct_pattern)
        return "--"
     end
     end


     -- Extract the rank from the row
     mw.log("Player rank found: ", rank)
    local rank_pattern = "|%s*(%d+)%s*|"
     return rank
    local rank = string.match(string.sub(content, start_pos, end_pos), rank_pattern)
     return rank or "Rank not found"
end
end


return p
return p

Поточна версія на 09:54, 12 травня 2024

Документацію для цього модуля можна створити у Модуль:FetchData/документація

local p = {}

function p.season_result(frame)
    local season = frame.args.season
    local player = frame.args.player

    -- Updated list of seasons with new entries
    local season_titles = {
        "Перший_сезон", "Другий_сезон", "Третій_сезон",
        "Четвертий_сезон", "П'ятий_сезон", "Шостий_сезон", 
        "Сьомий_сезон", "Восьмий_сезон", "Дев'ятий_сезон"
    }

    mw.log("Season index: ", season)
    mw.log("Player name: ", player)

    local season_title = season_titles[tonumber(season)]
    mw.log("Season page title: ", season_title)

    if not season_title then
        return "??"
    end

    local title = mw.title.new(season_title)
    local content = title and title:getContent()

    if not content then
        mw.log("Error: Content not found for the season page.")
        return "??"
    end

    mw.log("Page content loaded, length: ", string.len(content))
    mw.log("Page content preview: ", mw.ustring.sub(content, 1, 500))

    -- Attempt to extract the "Рейтинг" section
    local rating_section = mw.ustring.match(content, "==%s*Рейтинг%s*==.-{|%s*class%s*=%s*\"wikitable sortable\"(.-)|}")
    if not rating_section then
        mw.log("Error: Rating section not found within the page content.")
        mw.log("Page content: ", mw.ustring.sub(content, 1, 1000)) -- Log more content for better debugging
        return "Rating section not found"
    end

    mw.log("Rating section extracted, length: ", string.len(rating_section))
    mw.log("Rating section preview: ", mw.ustring.sub(rating_section, 1, 500))

    -- Adjusted to fetch the player's position (column 1 "№") instead of points
    local pattern = "|%s*(%d+)%s*|%s*%[%[" .. mw.ustring.gsub(player, "([%(%)%.%-%+%[%]])", "%%%1") .. "%]%]"
    local direct_pattern = "|%s*(%d+)%s*|%s*" .. mw.ustring.gsub(player, "([%(%)%.%-%+%[%]])", "%%%1") .. "%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.")
        mw.log("Pattern used: ", pattern)
        mw.log("Direct pattern used: ", direct_pattern)
        return "--"
    end

    mw.log("Player rank found: ", rank)
    return rank
end

return p