Module:Indicator datasets table: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
function p.getDatasets(frame) | function p.getDatasets(frame) | ||
local articleids = frame.args.articleids | local articleids = frame.args.articleids | ||
if not articleids then | if not articleids then | ||
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 | for _, id in ipairs(ids) do | ||
-- | -- Konstruieren des Seitentitels anhand der Page-ID | ||
local page = mw.title.new(nil, nil, tonumber(id)) | |||
local page = mw.title.new( | |||
if page and page.exists then | if page and page.exists then | ||
local content = page:getContent() | local content = page:getContent() | ||
local jsonData = mw.text.jsonDecode(content) | local jsonData = mw.text.jsonDecode(content) | ||
if jsonData and jsonData.date then | if jsonData and jsonData.date then | ||
table.insert(dates, jsonData.date) | table.insert(dates, jsonData.date) | ||
else | else | ||
table.insert(dates, "Error: Datum nicht gefunden für ID " .. id) | table.insert(dates, "Error: Datum nicht gefunden für ID " .. id) | ||
end | end | ||
else | else | ||
table.insert(dates, "Error: Seite nicht gefunden für ID " .. id) | table.insert(dates, "Error: Seite nicht gefunden für ID " .. id) | ||
end | end | ||
end | end | ||
return table.concat(dates, ", ") | return table.concat(dates, ", ") | ||
end | end | ||
return p | return p | ||
Revision as of 10:59, 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 page = mw.title.new(nil, nil, tonumber(id))
if page and page.exists then
local content = page:getContent()
local jsonData = mw.text.jsonDecode(content)
if jsonData and jsonData.date then
table.insert(dates, jsonData.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
end
return table.concat(dates, ", ")
end
return p