Modul:Data/DE-096775621/1/15

aus Wikipedia, der freien Enzyklopädie
local p = {}
local tData = {
	["rootfield"] = {
		["access date"] = "2017-02-20",
		["Einwohnerzahlen date"] = "1995-01-01",
		["page"] = "http://www.vgem-marktheidenfeld.de/verwalt/EWzahlen.htm",
		["publisher"] = "Verwaltungsgemeinschaft Marktheidenfeld",
		["title"] = "Entwicklung der Einwohnerzahlen seit 1981",
		["url"] = "http://www.vgem-marktheidenfeld.de/verwalt/EWzahlen.htm",
	},
	["value"] = {
		["Birkenfeld"]=1591,
		["Billingshausen"]=443,
		["Gemeinde Birkenfeld"]=2034,
		["Bischbrunn"]=1025,
		["Oberndorf"]=896,
		["Gemeinde Bischbrunn"]=1921,
		["Erlenbach"]=1670,
		["Tiefenthal"]=617,
		["Gemeinde Erlenbach"]=2287,
		["Esselbach"]=996,
		["Kredenbach"]=538,
		["Steinmark"]=561,
		["Gemeinde Esselbach"]=2095,
		["Hafenlohr"]=1441,
		["Windheim"]=434,
		["Gemeinde Hafenlohr"]=1875,
		["Karbach"]=1465,
		["Roden"]=552,
		["Ansbach"]=470,
		["Gemeinde Roden"]=1022,
		["Rothenfels"]=456,
		["Bergrothenfels"]=637,
		["Stadt Rothenfels"]=1093,
		["Urspringen"]=1265,
		["VG"]=15057,
	},
	["valuefield"] = {
		[""] = 1,
		["Einwohnerzahlen"] = 1,
	},
}

function p.getData(tArgs)
	if type(tArgs) == type({}) then
		local sArgs ="\n* fieldError\n* keyError\n* arg1"
		local tClip = {tData["value"][tArgs.key]}
		if tArgs.tryOther and not tClip then
			local b, tSub = pcall(require, "Module:Data/DE-096775621/1/14")
			if type(tSub) == type({}) and tSub.getData then
				return tSub.getData(tArgs)
			end
		end
		tArgs.field = tArgs.field or ""
		if tData["rootfield"][tArgs.field] then
			return tData["rootfield"][tArgs.field]
		elseif tArgs.field == "field list" then
			local s = "* field list\n*key table" .. sArgs
			local t = {}
			for i, v in pairs(tData["rootfield"]) do
				t[#t + 1] = i
			end
			table.sort(t)
			for i, v in pairs(t) do
				s = s .. "\n* " .. v
			end
			t = {}
			for i, v in pairs(tData["valuefield"]) do
				t[#t + 1] = i
			end
			table.sort(t)
			for i, v in pairs(t) do
				s = s .. "\n* " .. v
			end
			return s
		elseif tArgs.field == "key table" then
			local s = '{| class="wikitable"\n!key\n'
			local t = {}
			for i, v in pairs(tData["value"]) do
				t[#t + 1] = {i}
			end
			table.sort(t, function(t1 ,t2) return t1[1] < t2[1] end)
			for i, v in pairs(t) do
				s = s .. "|-\n|" .. v[1] .. "\n"
			end
			return s .. "|}"
		elseif (sArgs .. "\n"):find("\n* " .. tArgs.field .. "\n", 1 ,true) then
			return tArgs[tArgs.field]
		elseif not tClip then
			tArgs.keyError = tArgs.keyError or '<span class="error">key = ""</span>'
			return tArgs.keyError
		elseif tData["valuefield"][tArgs.field] then
			return tClip[tData["valuefield"][tArgs.field]]
		else
			tArgs.fieldError = tArgs.fieldError or '<span class="error">field = "field list"</span>'
			return tArgs.fieldError
		end
	else
		return '<span class="error">tArgs = {}</span>'
	end
end

function p.invokeData(frame)
	local t = {}
	t.key = frame.args[1] or frame.args["key"]
	t.field = frame.args[2] or frame.args["field"]
	for i, v in pairs(frame.args) do
		t[i] = t[i] or v
	end
	return p.getData(t)
end

return p