Module:Indicator datasets table: Difference between revisions

From Visual Data Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
function p.getDatasets(frame)
    local articleids = frame.args.articleids
    if not articleids then
        return "Error: articleids not provided"
    end
    local ids = mw.text.split(articleids, ",")
    local dates = {}
    for _, id in ipairs(ids) do
        local p = {}


function p.getDatasets(frame)
function p.getDatasets(frame)
Line 10: Line 20:
     for _, id in ipairs(ids) do
     for _, id in ipairs(ids) do
         -- Konstruieren des Seitentitels anhand der Page-ID
         -- Konstruieren des Seitentitels anhand der Page-ID
         local page = mw.title.new(562)
         local titleobject = mw.title.new( tonumber(id) )
        -- local page = mw.title.new( tonumber(id) )
--Doesn't use a colon
        if page and page.exists then
local existspage = titleobject.exists
            --local content = mw.text.getContent(page)
local pagecontent
            --local jsonData = mw.text.jsonDecode(content)
            local jsonData = page:getContent()
if existspage then
            --local jsonData = mw.text.jsonDecode(content)
-- Method uses a colon
            if jsonData and jsonData.Dataset.date then
  pagecontent = titleobject:getContent()
              table.insert(dates, jsonData.Dataset.date)
end
            else
                table.insert(dates, "Error: Datum nicht gefunden für ID " .. id)
return pagecontent
            end
    end
        else
end
            table.insert(dates, "Error: Seite nicht gefunden für ID " .. id)
 
        end
return p
 
     end
     end
     return table.concat(dates, ", ")
     return table.concat(dates, ", ")

Revision as of 13:12, 2 May 2024

Documentation for this module may be created at Module:Indicator datasets table/doc

local p = {}

function p.getDatasets(frame)
    local articleids = frame.args.articleids
    if not articleids then
        return "Error: articleids not provided"
    end
    local ids = mw.text.split(articleids, ",")
    local dates = {}
    for _, id in ipairs(ids) do
        local p = {}

function p.getDatasets(frame)
    local articleids = frame.args.articleids
    if not articleids then
        return "Error: articleids not provided"
    end
    local ids = mw.text.split(articleids, ",")
    local dates = {}
    for _, id in ipairs(ids) do
        -- Konstruieren des Seitentitels anhand der Page-ID
        local titleobject = mw.title.new( tonumber(id) )
		--Doesn't use a colon
		local existspage = titleobject.exists
		local pagecontent
		
		if existspage then
		-- Method uses a colon
		  pagecontent = titleobject:getContent()
		end
		
		return pagecontent
    end
end

return p

    end
    return table.concat(dates, ", ")
end

return p