Module:YouTubeSubscribers: Difference between revisions

Content deleted Content added
m Improve readability of long, compound if-statements
 
(One intermediate revision by one other user not shown)
Line 108:
end
local pointInTime = pointsInTime[1]
if pointInTime and
pointInTime['datavalue'] and
pointInTime['datavalue']['value'] and
pointInTime['datavalue']['value']['time']
then
return parseDate(pointInTime['datavalue']['value']['time'])
end
Line 171 ⟶ 175:
qid = mw.wikibase.getEntityIdForCurrentPage()
end
if not qid then
assert(qid, "No qid found for page. Please make a Wikidata item for this article")
local e = nil
return e
end
local e = mw.wikibase.getEntity(qid)
assert(e, "No such item found: " .. qid)
Line 182 ⟶ 189:
if #chanIds == 1 then
local chan = chanIds[1]
if chan and
chan["mainsnak"] and
chan["mainsnak"]["datavalue"] and
chan["mainsnak"]["datavalue"]["value"]
then
return chan["mainsnak"]["datavalue"]["value"]
end
Line 196 ⟶ 207:
function p.date( frame )
local e = getEntity(frame)
assert(qide, "No qid found for page. Please make a Wikidata item for this article")
local chanId = getBestYtChanId(e)
assert(chanId, "Could not find a single best YouTube channel ID for this item. Add a YouTube channel ID or set the rank of one channel ID to be preferred")
Line 229 ⟶ 241:
-- the most up to date number of subscribers
function p.subCount( frame )
local e = getEntity(frame)
local subCount = nil
local e = getEntity(frame)
if not e then
subCount = -424
return tonumber(subCount)
end
local chanId = getBestYtChanId(e)
if chanId then
local s = newestMatching(e, SUB_COUNT_PID, YT_CHAN_ID_PID, chanId)
if s and
if s and s["mainsnak"] and s['mainsnak']["datavalue"] and s['mainsnak']["datavalue"]["value"] and s['mainsnak']["datavalue"]['value']['amount'] then
s["mainsnak"] and
s['mainsnak']["datavalue"] and
s['mainsnak']["datavalue"]["value"] and
s['mainsnak']["datavalue"]['value']['amount']
then
subCount = s['mainsnak']["datavalue"]['value']['amount']
end