Module:Live song counter: Difference between revisions
Tag: Undo |
No edit summary Tag: Reverted |
||
Line 13: | Line 13: | ||
for i, song in ipairs(args) do | for i, song in ipairs(args) do | ||
if song and song ~= "" then | if song and song ~= "" then | ||
local songLink = | -- Keep the original songLink format as requested | ||
local songLink = "[[" .. song .. "]]" | |||
-- Times performed | -- Times performed | ||
local timesPerformed = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|format=count}}') | local timesPerformed = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|format=count}}') | ||
-- Check if times performed is 0 | |||
if timesPerformed == "0" then | |||
timesPerformed = "0" -- You can replace this with whatever you want to show for zero times performed | |||
end | |||
-- Earliest known performance | -- Earliest known performance | ||
local earliestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert date=|sort=Concert date|order=asc|limit=1|link=none|searchlabel=|mainlabel=-}}') | local earliestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert date=|sort=Concert date|order=asc|limit=1|link=none|searchlabel=|mainlabel=-}}') | ||
local earliestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=asc|mainlabel=-|limit=1|searchlabel=}}') | local earliestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=asc|mainlabel=-|limit=1|searchlabel=}}') | ||
local earliest = earliestDate .. ' in ' .. earliestCity | local earliest = "" | ||
if timesPerformed > "0" then | |||
earliest = earliestDate .. ' in ' .. earliestCity | |||
else | |||
earliest = "No known performances" | |||
end | |||
-- Latest known performance | -- Latest known performance | ||
local latestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|sort=Concert date|order=desc|limit=1|format=inline|searchlabel=|template=Date format}}') | local latestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|sort=Concert date|order=desc|limit=1|format=inline|searchlabel=|template=Date format}}') | ||
local latestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=desc|mainlabel=-|limit=1|searchlabel=}}') | local latestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=desc|mainlabel=-|limit=1|searchlabel=}}') | ||
local latest = latestDate .. ' in ' .. latestCity | local latest = "" | ||
if timesPerformed > "0" then | |||
latest = latestDate .. ' in ' .. latestCity | |||
else | |||
latest = "No known performances" | |||
end | |||
output = output .. '\n|-\n| ' .. songLink | output = output .. '\n|-\n| ' .. songLink |
Revision as of 18:11, 7 April 2025
Documentation for this module may be created at Module:Live song counter/doc
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(args, frame)
end
function p._main(args, frame)
local output = '{| class="wikitable sortable"'
output = output .. '\n! Song !! Times performed !! Earliest known performance !! Latest known performance'
for i, song in ipairs(args) do
if song and song ~= "" then
-- Keep the original songLink format as requested
local songLink = "[[" .. song .. "]]"
-- Times performed
local timesPerformed = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|format=count}}')
-- Check if times performed is 0
if timesPerformed == "0" then
timesPerformed = "0" -- You can replace this with whatever you want to show for zero times performed
end
-- Earliest known performance
local earliestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert date=|sort=Concert date|order=asc|limit=1|link=none|searchlabel=|mainlabel=-}}')
local earliestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=asc|mainlabel=-|limit=1|searchlabel=}}')
local earliest = ""
if timesPerformed > "0" then
earliest = earliestDate .. ' in ' .. earliestCity
else
earliest = "No known performances"
end
-- Latest known performance
local latestDate = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|sort=Concert date|order=desc|limit=1|format=inline|searchlabel=|template=Date format}}')
local latestCity = frame:preprocess('{{#ask:[[Live song::' .. song .. ']]|?Concert city=|sort=Concert date|order=desc|mainlabel=-|limit=1|searchlabel=}}')
local latest = ""
if timesPerformed > "0" then
latest = latestDate .. ' in ' .. latestCity
else
latest = "No known performances"
end
output = output .. '\n|-\n| ' .. songLink
output = output .. ' || style="text-align:center;" | ' .. timesPerformed
output = output .. ' || ' .. earliest
output = output .. ' || ' .. latest
end
end
output = output .. '\n|}'
return output
end
return p