Jump to content

Module:SongContestData

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by TheThomanski (talk | contribs) at 22:43, 14 March 2025. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local getArgs = require('Module:Arguments').getArgs
local p = {}

local function tableToString(t)
    local result = {}
    for _, v in pairs(t) do
        table.insert(result, tostring(v))
    end
    return table.concat(result, ";")
end

local function getData(contest, year)
	return mw.loadData('Module:SongContestData/'..contest..'/'..year)
end

function p.main(f)
	local args    = getArgs(f)
	local contest = args[1]
	local year    = args[2]
	local entry   = args[3]
	local att     = args[4]
	local data    = getData(contest, year)

    local result = ""
	for k, v in pairs(data[entry]) do
		if (k == att) then
			if type(v) == "table" then
				result = tableToString(v)
				break
			end
			result = v
			break
		end
	end
	return result
end

function p.entryAmount(f)
	local data = getData(getArgs(f)[1], getArgs(f)[2])
	local amount = 0
	for _ in pairs(data) do amount = amount + 1 end
	return amount
end
	
return p