Jump to content

Module:NPP backlog

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Joe Roe (talk | contribs) at 11:15, 19 June 2023 (Check for nil in day2). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {};

local data = mw.loadJsonData("Wikipedia:New pages patrol/Backlog chart/daily")

local backlog = { }
for k,v in ipairs(data) do
	backlog[v["date"]] = v["value"]
end

function p._articles(day1, day2)
	if day2 == nil then
		return backlog[day1] or 0
	else
		if (backlog[day1] == nil or backlog[day2] == nil) then
			return 0
		else
			return backlog[day1] - backlog[day2]
		end
	end
end

function p.articles(frame)
	local templateArgs = frame.args
	local day1 = templateArgs[1] or os.date("%Y-%m-%d")
	local day2 = templateArgs[2] or nil
	return p._articles(day1, day2)
end

return p