Jump to content

Module:CIA World Factbook

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hike395 (talk | contribs) at 20:44, 26 September 2022 (filter out recent years). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local getArgs = require('Module:Arguments').getArgs

local urlPrefix = 'https://www.cia.gov/the-world-factbook/about/archives/download/factbook-'
local urlSuffix = '.zip'

function p._archive(args)
	if args.archive then
		return nil
	end
	local year = nil
	if args.year then
		year = tonumber(args.year)
	elseif args.date then
		i, j = mw.ustring.find(args.date,'20%d%d')
		if i and j then
			year = tonumber(mw.ustring.sub(args.date,i,j))
		end
	end
	if not year then
		return year
	end
	if year+1 >= tonumber(os.date('%Y')) then
		return false
	end
	return urlPrefix..year..urlSuffix
end

function p.archive(frame)
	local args = getArgs(frame)
	return p._archive(args) or ''
end

return p