Modulo:Sandbox/RiccardoFila

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca
-- La documentazione per questo modulo è disponibile su https://it.wikipedia.org/wiki/Utente:RiccardoFila#Offerte_speciali

local p = {}
local Date = require('Modulo:Data').Date

local function split(s, d)
	local res = {}
	for match in (s .. d):gmatch("(.-)" .. d) do
        table.insert(res, match)
    end
    return res
end

function p.data_odierna()
	return Date:new(nil):getDateString()
end

function p.cn(frame)
	local titolo = ''
	local url = split(frame.args[1], '/')
	if frame.args[2] then
		titolo = frame.args[2]
	else
		local titolourl = url[7]
		titolo = 'Cartoon News #'
		local i = 1
		for match in titolourl:gmatch("([^-]+)") do
			if i == 3 then
				titolo = titolo .. match .. ' – '
			elseif i == 4 then
				titolo = titolo .. match:gsub("^%l", string.upper) .. ' '
			elseif i > 4 then
				titolo = titolo .. match .. ' '
			end
			i = i + 1
		end
	end
	local data = Date:new(url[4] .. '/' .. url[5] .. '/' .. url[6]):getDateString()
	local accesso = Date:new(nil):getDateString()
	return '{{Cita web|url=' .. frame.args[1] .. ' |titolo=' .. titolo .. '|autore=Antonio Genna|data=' .. data .. '|accesso=' .. accesso .. '}}'
end

function p.tabella(frame)
	if frame.args.righe == nil or frame.args.colonne == nil then
		return "Errore: specificare il numero di righe e di colonne"
	end
	local righe = tonumber(frame.args.righe)
	local colonne = tonumber(frame.args.colonne)
	
	local contenuti = {}
	local rowspan = {}
	local inizio = {}
	local inc = {}
	local out = ""
	local index
	
	for k, v in pairs(frame.args) do
		--out = out .. k .. "=" .. v .. "\n"
		if k:find("rowspan") == 1 then
			index = tonumber(k:sub(8, 8))
			rowspan[index] = tonumber(v)
			contenuti[index] = contenuti[index] or "S"
		end
		if k:find("numero") == 1 then
			index = tonumber(k:sub(7, 7))
			inizio[index] = tonumber(v)
			contenuti[index] = "N"
		end
		if k:find("corsivo") == 1 then
			index = tonumber(k:sub(8, 8))
			contenuti[index] = "C"
		end
		if k:find("data") == 1 then
			index = tonumber(k:sub(5, 5))
			inizio[index] = Date:new(v)
			contenuti[index] = "D"
			if inc[index] == nil then inc[index] = 7 end
		end
		if k:find("incremento") == 1 then
			index = tonumber(k:sub(11, 11))
			inc[index] = tonumber(v)
		end
	end
	
	out = out .. "{| class=\"wikitable\"\n"
	local separatore = '!'
	local k, rs
	
	for i = 0, righe, 1 do
		if i > 0 then
			separatore = '|'
			out = out .. "|-\n"
		end
		k = 0
		for j = 1, colonne, 1 do
			-- apertura cella
			if i == 0 or contenuti[j] == nil or math.fmod(i - 1, rowspan[j] or 1) == 0 then
				if k == 0 then
					out = out .. separatore
				else
					out = out .. ' ' .. separatore .. separatore
				end
				k = k + 1
				
				-- rowspan
				rs = rowspan[j] or 1
				if rs > righe - i + 1 then
					rs = righe - i + 1
				end
				if i > 0 and rs > 1 then
					out = out .. "rowspan=" .. rs .. "| "
				else
					out = out .. " "
				end
				
				-- contenuto
				if contenuti[j] ~= nil then
					if i == 0 then
						if contenuti[j] == "N" then out = out .. "Nº" end
						if contenuti[j] == "C" then out = out .. "Titolo" end
						if contenuti[j] == "D" then out = out .. "Prima TV" end
					else
						if contenuti[j] == "N" then
							out = out .. ((i - 1) / (rowspan[j] or 1)) + inizio[j]
						end
						if contenuti[j] == "C" then
							out = out .. "''''"
						end
						if contenuti[j] == "D" then
							out = out .. inizio[j]:getDateString()
							inizio[j] = inizio[j]:addDays(inc[j])
						end
					end
				end
			end
		end
		out = out .. "\n"
	end
	out = out .. "|}\n"
	return out
end

function p.tabellaanime(frame)
	if frame.args.numero_episodi == nil then
		return "Errore: specificare il numero di episodi compilando il campo \"numero_episodi\"."
	end
	local numero_episodi = tonumber(frame.args.numero_episodi)
	local inizio_episodi = frame.args.inizio_episodi == nil and 1 or tonumber(frame.args.inizio_episodi)
	
	local titoli = ''
	if frame.args.titolo ~= nil then
		if string.find(frame.args.titolo, 'i') then
			titoli = titoli .. "|titolo italiano = \n"
		end
		if string.find(frame.args.titolo, 'k') then
			titoli = titoli .. "|titolo kanji = \n"
		end
		if string.find(frame.args.titolo, 'r') then
			titoli = titoli .. "|titolo romaji = \n"
		end
		if string.find(frame.args.titolo, 't') then
			titoli = titoli .. "|titolo traduzione = \n"
		end
	end
	
	local data = {false, false}
	local data_str = {'giappone' , 'italia'}
	local data_inc = {7, 7}
	for i = 1, 2 do
		if frame.args['data_' .. data_str[i]] ~= nil then
			if frame.args['data_' .. data_str[i]] == '-' then
				data[i] = '-'
			else
				if string.len(frame.args['data_' .. data_str[i]]) == 10 then
					data[i] = Date:new(frame.args['data_' .. data_str[i]])
					if frame.args['incremento_' .. data_str[i]] ~= nil then
						data_inc[i] = tonumber(frame.args['incremento_' .. data_str[i]])
					end
				else
					data[i] = ''
				end
			end
		end
	end
	
	local out = ""
	for i = 1, numero_episodi do
		out = out .. "{{Episodio Anime\n"
		if i == 1 then
			out = out .. (numero_episodi == 1 and "|posizione template = unico\n" or "|posizione template = testa\n")
		else
			if i == numero_episodi then
				out = out .. "|posizione template = coda\n"
			end
		end
		
		out = out .. "|numero episodio = " .. (inizio_episodi + i - 1) .. "\n"
		out = out .. titoli
		for j = 1, 2 do
			if data[j] ~= false then
				out = out .. "|data " .. data_str[j] .. " = "
				if data[j] == '-' then
					out = out .. "-\n"
				else
					if data[j] == '' then
						out = out .. "\n"
					else
						out = out .. data[j]:getDateString() .. "\n"
						data[j] = data[j]:addDays(data_inc[j])
					end
				end
			end
		end
		out = out .. "}}\n"
	end
	
	return out
end

function p.trame()
	-- 2018
	local t = 12 -- Dopo la pioggia
	+ 24 -- Darling in the Franxx
	+ 46 -- Mazinga Z
	+ 13 + 12 -- Made in Abyss
	+ 26 -- L'isola del tesoro 1978
	+ 13 -- A Place Further Than the Universe
	+ 4 -- (*) Violet Evergarden
	+ 7 + 10 + 6 -- Chiamatemi Anna
	+ 74 -- (*) Captain Tsubasa
	+ 20 -- Lupin III - Ritorno alle origini
	+ 12 -- Sword Art Online Alternative: Gun Gale Online
	+ 49 -- Clannad
	+ 50 -- Lucy May
	+ 24 -- Banana Fish
	+ 12 -- Children of the Whales
	+ 47 -- Sword Art Online: Alicization
	-- 2019
	+ 26 -- Kono oto tomare!
	+ 63 -- Fruits Basket 2019
	+ 11 -- Demon Slayer
	+ 0 + 7 + 25 + 0 + 25 -- My Hero Academia
	+ 26 -- Torna a casa Lassie!
	-- 2020
	+ 52 -- Fiocchi di cotone per Jeanie
	+ 24 + 1 -- Shirayuki dai capelli rossi
	-- 2021
	+ 100 -- Dragon Quest: L'avventura di Dai
	+ 12 -- Kemono jihen
	+ 24 + 11 + 1 + 22 -- Dr. Stone
	+ 24 -- Cuore
	+ 26 -- Megalo Box
	+ 20 + 20 -- To Your Eternity
	+ 12 -- Super Cub
	+ 24 -- The Aquatope on White Sand
	+ 24 -- Yashahime: Princess Half-Demon st.2
	-- 2022
	+ 25 -- (*) Yu Yu Hakusho: Ghost Files
	+ 1 -- OAV Kill la Kill
	+ 24 -- Le dimostrazioni di Lui & Lei
	+ 24 -- Tokyo Mew Mew New
	+ 24 -- Jujutsu kaisen
	+ 10 -- (*) World of Winx
	+ 9 -- Il mondo di Peter Coniglio e dei suoi amici
	-- 2023
	+ 24 + 1 -- Mobile Suit Gundam: The Witch from Mercury
	-- 2024
	+ 10 -- (*) Il segreto della sabbia
	return t
end

return p