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()
function p.getDatasets(frame)
     local jsonPage = mw.title.new("Entry:Datasets/Dataset")
    -- Extrahiere die articleids aus dem frame
    if jsonPage and jsonPage.exists then
     local articleids = frame.args.articleids
        local content = jsonPage:getContent()
    -- Überprüfe, ob articleids vorhanden sind
        local jsonData = mw.text.jsonDecode(content)
    if not articleids then
        if jsonData and jsonData.schemas and jsonData.schemas.Dataset then
        return "Error: articleids not provided"
             return jsonData.schemas.Dataset.date
    end
    -- Teile die articleids anhand des Kommas auf
    local ids = mw.text.split(articleids, ",")
    local dates = {}
    -- Durchlaufe jede id und suche die entsprechende Seite
    for _, id in ipairs(ids) do
        -- Konstruiere den Seitentitel
        local pageTitle = "Entry:Datasets/Dataset " .. id
        -- Versuche, die Seite zu laden
        local page = mw.title.new(pageTitle)
        if page and page.exists then
            -- Holen Sie sich den Inhalt der Seite und analysieren Sie ihn als JSON
            local content = page:getContent()
            local jsonData = mw.text.jsonDecode(content)
            -- Überprüfe, ob das Datum im JSON-Datenobjekt vorhanden ist
            if jsonData and jsonData.date then
                -- Füge das Datum der Ergebnisliste hinzu
                table.insert(dates, jsonData.date)
             else
                -- Wenn das Datum nicht gefunden wurde, füge eine Fehlermeldung hinzu
                table.insert(dates, "Error: Datum nicht gefunden für ID " .. id)
            end
         else
         else
             return "Error: Invalid JSON structure"
             -- Wenn die Seite nicht gefunden wurde, füge eine Fehlermeldung hinzu
            table.insert(dates, "Error: Seite nicht gefunden für ID " .. id)
         end
         end
    else
        return "Error: JSON page does not exist"
     end
     end
    -- Gib die Ergebnisse zurück, getrennt durch ein Komma
    return table.concat(dates, ", ")
end
end


return p
return p

Revision as of 10:57, 2 May 2024

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

local p = {}

function p.getDatasets(frame)
    -- Extrahiere die articleids aus dem frame
    local articleids = frame.args.articleids
    -- Überprüfe, ob articleids vorhanden sind
    if not articleids then
        return "Error: articleids not provided"
    end
    -- Teile die articleids anhand des Kommas auf
    local ids = mw.text.split(articleids, ",")
    local dates = {}
    -- Durchlaufe jede id und suche die entsprechende Seite
    for _, id in ipairs(ids) do
        -- Konstruiere den Seitentitel
        local pageTitle = "Entry:Datasets/Dataset " .. id
        -- Versuche, die Seite zu laden
        local page = mw.title.new(pageTitle)
        if page and page.exists then
            -- Holen Sie sich den Inhalt der Seite und analysieren Sie ihn als JSON
            local content = page:getContent()
            local jsonData = mw.text.jsonDecode(content)
            -- Überprüfe, ob das Datum im JSON-Datenobjekt vorhanden ist
            if jsonData and jsonData.date then
                -- Füge das Datum der Ergebnisliste hinzu
                table.insert(dates, jsonData.date)
            else
                -- Wenn das Datum nicht gefunden wurde, füge eine Fehlermeldung hinzu
                table.insert(dates, "Error: Datum nicht gefunden für ID " .. id)
            end
        else
            -- Wenn die Seite nicht gefunden wurde, füge eine Fehlermeldung hinzu
            table.insert(dates, "Error: Seite nicht gefunden für ID " .. id)
        end
    end
    -- Gib die Ergebnisse zurück, getrennt durch ein Komma
    return table.concat(dates, ", ")
end

return p