Módulo:Teste: diferenças entre revisões
Saltar para a navegação
Saltar para a pesquisa
Sem resumo de edição |
Sem resumo de edição |
||
Linha 10: | Linha 10: | ||
function p.getQualifiers(frame) | function p.getQualifiers(frame) | ||
local data_str = nil | |||
local num_residencia = frame.args.numresidencia | |||
local cod_propriedade = frame.args.propriedade | |||
local entity = mw.wikibase.getEntity(frame.args[1]) | |||
if (entity['claims']['P26'][tonumber(num_residencia)]['qualifiers'][cod_propriedade] ~= nil) then | |||
local snak = entity['claims']['P26'][tonumber(num_residencia)]['qualifiers'][cod_propriedade][1]['datavalue']['value']['time'] | |||
_,_,y,m,d=string.find(snak, "(%d+)-(%d+)-(%d+)") | |||
if (tonumber(d) and tonumber(m) and tonumber(y) > 0) then | |||
data_str = d .. '/' .. m .. '/' .. y | |||
elseif (tonumber(m) and tonumber(y) > 0) then | |||
data_str = m .. '/' .. y | |||
elseif (tonumber(y) > 0) then | |||
data_str = y | |||
end | |||
end | |||
return data_str | |||
end | end | ||
return p | return p |
Revisão das 22h28min de 12 de maio de 2020
A documentação para este módulo pode ser criada na página Módulo:Teste/doc
local p = {} function p.getResidenciaNome(frame) local residencia = frame.args.res local entity = mw.wikibase.getEntity(frame.args[1]) local nome_residencia = entity['claims']['P26'][tonumber(residencia)]['mainsnak']['datavalue']['value']['id'] return nome_residencia end function p.getQualifiers(frame) local data_str = nil local num_residencia = frame.args.numresidencia local cod_propriedade = frame.args.propriedade local entity = mw.wikibase.getEntity(frame.args[1]) if (entity['claims']['P26'][tonumber(num_residencia)]['qualifiers'][cod_propriedade] ~= nil) then local snak = entity['claims']['P26'][tonumber(num_residencia)]['qualifiers'][cod_propriedade][1]['datavalue']['value']['time'] _,_,y,m,d=string.find(snak, "(%d+)-(%d+)-(%d+)") if (tonumber(d) and tonumber(m) and tonumber(y) > 0) then data_str = d .. '/' .. m .. '/' .. y elseif (tonumber(m) and tonumber(y) > 0) then data_str = m .. '/' .. y elseif (tonumber(y) > 0) then data_str = y end end return data_str end return p