Modulo:Sandbox/ValterVB/Tracklist: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
.
Omega Bot (discussione | contributi)
m Bot: rimuovo no globals obsoleto
 
(24 versioni intermedie di 2 utenti non mostrate)
Riga 1:
require('strict')
local getArgs = require('Module:Arguments').getArgs
local mWikidata = require('Modulo:Wikidata')
local p = {}
 
function p.main(frame)
local food = {
local t = getArgs(frame)
{category = "Bread", name = "white"},
local dato = t[1]
{category = "drinks", name = "milk"},
local tracce1 = {}
{category = "Bread", name = "corn"},
local tracce2 = {}
{category = "Bread", name = "french"},
local i
{category = "drinks", name = "cola"},
local ss
{category = "drinks", name = "soda"}
local wdTracce, wdAutori, wdParole, wdBasatoSu
}
local ordine, ddato, titolo, durata
local ret
wdTracce = mWikidata._getClaims('P658', { from = dato })
 
if wdTracce then
local function tableSortCat( a, b )
 
return (a.category < b.category) or (a.category == b.category and a.name < b.name)
for _, traccia in ipairs(wdTracce) do
end
ss = ''
 
titolo = mWikidata._formatStatement(traccia)
 
ordine = mWikidata._formatQualifiers(traccia, 'P1545')
 
if (ordine and tonumber(ordine)) then
ordine = tonumber(ordine)
ss = ordine
else
ordine = -1
ss = '-'
end
 
durata = mWikidata._formatQualifiers(traccia, 'P2047')
if durata == nil then
durata = 'n.d.'
else
durata = tonumber(durata) or 0
if (durata > 59) then
durata = math.floor(durata/60) .. '\' ' .. (durata - 60*math.floor(durata/60)) .. '"'
else
durata = durata .. '"'
end
end
 
ss = ss .. '. \'\'' .. titolo .. '\'\' (' .. durata .. ')'
 
if traccia.mainsnak.datavalue.value.id then
ddato = traccia.mainsnak.datavalue.value.id
wdAutori = mWikidata._getClaims('P86', { from = ddato })
if #wdAutori > 0 then
ss = ss .. ' <small>Comp.: '
i = 1
for _, autore in ipairs(wdAutori) do
if (i>1) then ss = ss .. ', ' end
i = i + 1
ss = ss .. mWikidata._formatStatement(autore)
end
ss = ss .. '</small>'
end
wdParole = mWikidata._getClaims('P676', { from = ddato })
if #wdParole > 0 then
ss = ss .. ' <small>Parol.: '
i = 1
for _, parola in ipairs(wdParole) do
if (i>1) then ss = ss .. ', ' end
i = i + 1
ss = ss .. mWikidata._formatStatement(parola)
end
ss = ss .. '</small>'
end
wdBasatoSu = mWikidata._getClaims('P144', { from = ddato })
if next(wdBasatoSu) ~= nil then
ss = ss .. ' <small>Basato su: '
i = 1
for _, basato in ipairs(wdBasatoSu) do
if (i>1) then ss = ss .. ', ' end
i = i + 1
ss = ss .. mWikidata._formatStatement(basato)
end
ss = ss .. '</small>'
end
end
 
if (ordine == -1) then
table.insert(tracce2,ss)
else
tracce1[ordine] = ss
end
 
end
 
function p.main(frame)
table.sort( food, tableSortCat )
--for i=1, #food do
-- print(food[i].category, food[i].name)
--end
ss = ''
for k, v in pairs( food ) do
ss = ss .. k .. ',' .. v .. '<br/>'
end
 
return ss
ret = {}
for _,k in ipairs(tracce1) do
table.insert(ret,k..'<br/>')
end
for _,k in ipairs(tracce2) do
table.insert(ret,k..'<br/>')
end
 
return table.concat(ret)
 
end