Module:Indicator datasets table: Difference between revisions

From Visual Data Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 6: Line 6:
         return "Error: articleids not provided"
         return "Error: articleids not provided"
     end
     end
   
     local ids = mw.text.split(articleids, ",")
     local ids = mw.text.split(articleids, ",")
     local dates = {}
     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
     for _, id in ipairs(ids) do
         -- Konstruieren des Seitentitels anhand der Page-ID
         -- Konstruieren des Seitentitels anhand der Page-ID
         local titleobject = mw.title.new( tonumber(id) )
         local titleobject = mw.title.new("", "Entry", tonumber(id))
--Doesn't use a colon
       
local existspage = titleobject.exists
        if titleobject then
local pagecontent
            local existspage = titleobject.exists
           
if existspage then
            if existspage then
-- Method uses a colon
                local pagecontent = titleobject:getContent()
  pagecontent = titleobject:getContent('date')
                local jsonData = mw.text.jsonDecode(pagecontent)
end
               
                if jsonData and jsonData.Dataset and jsonData.Dataset.date then
return pagecontent
                    table.insert(dates, jsonData.Dataset.date)
    end
                else
end
                    table.insert(dates, "Error: Datum nicht gefunden für ID " .. id)
 
                end
return p
            else
 
                table.insert(dates, "Error: Seite nicht gefunden für ID " .. id)
            end
        else
            table.insert(dates, "Error: Fehler beim Erstellen des Titels für ID " .. id)
        end
     end
     end
   
     return table.concat(dates, ", ")
     return table.concat(dates, ", ")
end
end


return p
return p

Revision as of 13:19, 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
        -- Konstruieren des Seitentitels anhand der Page-ID
        local titleobject = mw.title.new("", "Entry", tonumber(id))
        
        if titleobject then
            local existspage = titleobject.exists
            
            if existspage then
                local pagecontent = titleobject:getContent()
                local jsonData = mw.text.jsonDecode(pagecontent)
                
                if jsonData and jsonData.Dataset and jsonData.Dataset.date then
                    table.insert(dates, jsonData.Dataset.date)
                else
                    table.insert(dates, "Error: Datum nicht gefunden für ID " .. id)
                end
            else
                table.insert(dates, "Error: Seite nicht gefunden für ID " .. id)
            end
        else
            table.insert(dates, "Error: Fehler beim Erstellen des Titels für ID " .. id)
        end
    end
    
    return table.concat(dates, ", ")
end

return p