-- Introduction to Lua in Wikipedia
local p =
-- Function to convert JSON data to a Lua tablefunction p.jsonToTable(jsonPage) -- Check if jsonPage is a valid string if type(jsonPage) ~= 'string' then return nil, "Invalid argument: JSON page name must be a string." end -- Try to load the page content local title = mw.title.new(jsonPage) if not title then return nil, "Failed to create title object for page: " .. jsonPage end
local content = title:getContent if not content then return nil, "Failed to load content for page: " .. jsonPage end
-- Try to decode the JSON content local data = mw.text.jsonDecode(content) if type(data) ~= 'table' then return nil, "Invalid JSON data in page: " .. jsonPage end
-- Initialize a Lua table to store the processed data local videosTable =
-- Loop over the JSON data and copy the entries to the Lua table for i, video in ipairs(data) do table.insert(videosTable,) end
return videosTable, nilend
-- Function to generate a wikitable from the filtered contentfunction p.generateWikitable(frame) local jsonPage = frame.args[1] if not jsonPage then return "Error: No JSON page specified." end
local videosTable, err = p.jsonToTable(jsonPage)
if not videosTable then return "Wikitable from JSON data error: " .. err end
local result = ") return table.concat(result, "\n")end
-- start Gemini Flash
function p.filterSongs(frame) local filters = frame.args local results = local index = 1 local maxEntries = 1000
while index <= maxEntries do local songData = frame:expandTemplate if not songData or songData
local dataParts = mw.text.split(songData, ";") local songInfo =
local match = true for key, value in pairs(filters) do if value ~= "" and songInfo[key] ~= value then match = false break end end
if match then table.insert(results, songInfo) end
index = index + 1 end
return resultsend
function p.displayWikitable(frame) local results = p.filterSongs(frame) local tableContent = ""
if #results > 0 then tableContent = "
Title | Artist | Year | Album\n" for _, song in ipairs(results) do tableContent = tableContent .. " | -\n" -- Add a new row tableContent = tableContent .. " | " .. song.Title .. " \n | " .. song.Artist .. " \n | " .. song.Year .. " \n | " .. song.Album .. "\n" end tableContent = tableContent .. " |
---|
return tableContentend
-- end Gemini Flash
function p.filterData(frame) local filters = frame.args local filteredResults = local index = 1 local maxEntries = 1000 -- Safety limit to prevent infinite loops
while index <= maxEntries do local songData = frame:expandTemplate if not songData or songData
local dataParts = mw.text.split(songData, ";") local songInfo = local match = true for key, value in pairs(filters) do if value ~= "" and songInfo[key] ~= value then match = false break end end
if match then table.insert(filteredResults, songInfo) end index = index + 1 end return filteredResultsend
function p.filterVideoData(frame) local filteredResults = local index = 1 local maxEntries = 1000 -- Safety limit to prevent infinite loops
while index <= maxEntries do local videoData = frame:expandTemplate if not videoData or videoData
local dataParts = mw.text.split(videoData, ";") local videoInfo = table.insert(filteredResults, videoInfo) index = index + 1 end return filteredResultsend
function p.display(frame) local filters = frame.args local result = "" local index = 1 local maxEntries = 1000 -- Safety limit to prevent infinite loops
while index <= maxEntries do local songData = frame:expandTemplate if not songData or songData
local dataParts = mw.text.split(songData, ";") local songInfo = local match = true for key, value in pairs(filters) do if value ~= "" and songInfo[key] ~= value then match = false break end end
if match then result = result .. frame:expandTemplate .. "
" end index = index + 1 end return resultend
return p