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

621 байт додано ,  У понеділок о 20:03
нема опису редагування
Немає опису редагування
Немає опису редагування
 
Рядок 19: Рядок 19:
end
end


local function count_facts(content, section_start)
local function get_section_content(content, section_start)
     local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1)
     local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1)
    local section_content
      
      
     if section_end then
     if section_end then
         section_content = mw.ustring.sub(content, section_start, section_end - 1)
         return mw.ustring.sub(content, section_start, section_end - 1)
     else
     else
         section_content = mw.ustring.sub(content, section_start)
         return mw.ustring.sub(content, section_start)
     end
     end
   
end
 
local function count_facts(section_content)
     local count = 0
     local count = 0
     for line in mw.ustring.gmatch(section_content, "[^\n]+") do
     for line in mw.ustring.gmatch(section_content, "[^\n]+") do
Рядок 35: Рядок 36:
         end
         end
     end
     end
      
     return count
end
 
local function count_awards(section_content)
    local count = 0
    for _ in mw.ustring.gmatch(section_content, "%[%[File:[^%]]+%.png") do
        count = count + 1
    end
     return count
     return count
end
end
Рядок 64: Рядок 72:
                 local display = processed
                 local display = processed
                  
                  
                 if mw.ustring.match(processed, "Цікаві факти") then
                 local section_pos = mw.ustring.find(content, line, 1, true)
                    local section_pos = mw.ustring.find(content, line, 1, true)
               
                     if section_pos then
                if section_pos then
                         local facts_count = count_facts(content, section_pos)
                    local section_content = get_section_content(content, section_pos)
                   
                     if mw.ustring.match(processed, "Цікаві факти") then
                         local facts_count = count_facts(section_content)
                         if facts_count > 0 then
                         if facts_count > 0 then
                             display = processed .. " (" .. facts_count .. ")"
                             display = processed .. " (" .. facts_count .. ")"
                        end
                    elseif mw.ustring.match(processed, "Нагороди") then
                        local awards_count = count_awards(section_content)
                        if awards_count > 0 then
                            display = processed .. " (" .. awards_count .. ")"
                         end
                         end
                     end
                     end