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

279 байтів вилучено ,  У неділю о 11:12
нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 58: Рядок 58:
     local table_content = mw.ustring.sub(rating_section, table_start, table_end + 1)
     local table_content = mw.ustring.sub(rating_section, table_start, table_end + 1)
      
      
     -- Шукаємо рядок з гравцем
     -- Розбиваємо таблицю на рядки (між |- )
     local rows = {}
    local current_row = {}
     for row in mw.ustring.gmatch(table_content, "|\n(.-)\n|%-") do
     local all_rows = {}
        table.insert(rows, row)
   
     for line in mw.ustring.gmatch(table_content .. "\n", "([^\n]*)\n") do
        line = mw.text.trim(line)
       
        if line == "|-" then
            if #current_row > 0 then
                table.insert(all_rows, current_row)
            end
            current_row = {}
        elseif mw.ustring.match(line, "^|[^-}]") then
            -- Це комірка (починається з | але не |- або |})
            local cell_content = mw.ustring.gsub(line, "^|%s*", "")
            table.insert(current_row, cell_content)
        end
     end
     end
      
      
     -- Додаємо останній рядок
     -- Додаємо останній рядок якщо є
    local last_row = mw.ustring.match(table_content, "|%-\n(.-)\n|}")
     if #current_row > 0 then
     if last_row then
         table.insert(all_rows, current_row)
         table.insert(rows, last_row)
     end
     end
      
      
     for _, row in ipairs(rows) do
    -- Шукаємо рядок з гравцем
         -- Перевіряємо чи є ім'я гравця в цьому рядку
     for _, row in ipairs(all_rows) do
        if mw.ustring.find(row, "%[%[" .. player_name .. "%]%]") then
         -- row[1] = №, row[2] = Пан/Пані, row[3] = Σ, row[4] = І, row[5] = %
            local cells = {}
        if #row >= 5 then
           
            local player_cell = clean_wikilinks(row[2])
            -- Розбиваємо рядок по | та ||
            for line in mw.ustring.gmatch(row .. "\n", "([^\n]+)\n") do
                line = mw.text.trim(line)
                if mw.ustring.match(line, "^|") then
                    -- Видаляємо початковий |
                    line = mw.ustring.gsub(line, "^|%s*", "")
                    table.insert(cells, line)
                end
            end
           
            -- Структура таблиці: №, Пан/Пані, Σ, І, %
            -- cells[1] = №
            -- cells[2] = Пан/Пані (з вікі-посиланням)
            -- cells[3] = Σ (бали)
            -- cells[4] = І (ігор)
            -- cells[5] = % (відсоток перемог)
              
              
             if #cells >= 5 then
             if player_cell == player_name then
                 return {
                 return {
                     place = mw.text.trim(cells[1]),
                     place = mw.text.trim(row[1]),
                     points = mw.text.trim(cells[3]),
                     points = mw.text.trim(row[3]),
                     games = mw.text.trim(cells[4]),
                     games = mw.text.trim(row[4]),
                     winrate = mw.text.trim(cells[5])
                     winrate = mw.text.trim(row[5])
                 }
                 }
             end
             end