Модуль:FetchData6: відмінності між версіями

нема опису редагування
(Створена сторінка: local p = {} --- Отримує дані гравця з конкретного сезону local function get_season_data(season_number, player_name) local season_names = { [1] = "Перший сезон", [2] = "Другий сезон", [3] = "Третій сезон", [4] = "Четвертий сезон", [5] = "П'ятий сезон", [6] = "Шостий сезон", [7] = "Сьомий...)
 
Немає опису редагування
Рядок 1: Рядок 1:
local p = {}
local p = {}
--- Видаляє вікі-посилання [[link]]
local function clean_wikilinks(text)
    if not text then return nil end
    text = mw.ustring.gsub(text, "%[%[([^%]|]+)|([^%]]+)%]%]", "%2")
    text = mw.ustring.gsub(text, "%[%[([^%]]+)%]%]", "%1")
    return mw.text.trim(text)
end


--- Отримує дані гравця з конкретного сезону
--- Отримує дані гравця з конкретного сезону
Рядок 31: Рядок 39:
      
      
     -- Знаходимо секцію "Рейтинг"
     -- Знаходимо секцію "Рейтинг"
     local rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.-)==")
     local rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.-)\n==")
     if not rating_section then
     if not rating_section then
         rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.*)")
         rating_section = mw.ustring.match(content, "==+%s*Рейтинг%s*==+(.*)")
Рядок 52: Рядок 60:
     -- Шукаємо рядок з гравцем
     -- Шукаємо рядок з гравцем
     local rows = {}
     local rows = {}
     for row in mw.ustring.gmatch(table_content, "|-\n(.-)\n|-") do
     for row in mw.ustring.gmatch(table_content, "|\n(.-)\n|%-") do
         table.insert(rows, row)
         table.insert(rows, row)
     end
     end
      
      
     local last_row = mw.ustring.match(table_content, "|-\n(.-)%s*|}")
    -- Додаємо останній рядок
     local last_row = mw.ustring.match(table_content, "|%-\n(.-)\n|}")
     if last_row then
     if last_row then
         table.insert(rows, last_row)
         table.insert(rows, last_row)
Рядок 65: Рядок 74:
         if mw.ustring.find(row, "%[%[" .. player_name .. "%]%]") then
         if mw.ustring.find(row, "%[%[" .. player_name .. "%]%]") then
             local cells = {}
             local cells = {}
            row = mw.ustring.gsub(row, "^%s*|%s*", "")
              
              
             for cell in mw.ustring.gmatch(row, "|%s*([^\n|]+)") do
            -- Розбиваємо рядок по | та ||
                 local trimmed = mw.text.trim(cell)
             for line in mw.ustring.gmatch(row .. "\n", "([^\n]+)\n") do
                 if trimmed ~= "" then
                 line = mw.text.trim(line)
                     table.insert(cells, trimmed)
                 if mw.ustring.match(line, "^|") then
                    -- Видаляємо початковий |
                    line = mw.ustring.gsub(line, "^|%s*", "")
                     table.insert(cells, line)
                 end
                 end
             end
             end
              
              
             -- cells[1] = №, cells[2] = Пан/Пані, cells[3] = Σ, cells[4] = І, cells[5] = %
            -- Структура таблиці: №, Пан/Пані, Σ, І, %
             -- cells[1] = №
            -- cells[2] = Пан/Пані (з вікі-посиланням)
            -- cells[3] = Σ (бали)
            -- cells[4] = І (ігор)
            -- cells[5] = % (відсоток перемог)
           
             if #cells >= 5 then
             if #cells >= 5 then
                 return {
                 return {