Module:YouTubeSubscribers

This is an old revision of this page, as edited by BrokenSegue (talk | contribs) at 00:56, 17 February 2023 (serializeTable). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {} 

function serializeTable(val, name, skipnewlines, depth)
    skipnewlines = skipnewlines or false
    depth = depth or 0

    local tmp = string.rep(" ", depth)

    if name then tmp = tmp .. name .. " = " end

    if type(val) == "table" then
        tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")

        for k, v in pairs(val) do
            tmp =  tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
        end

        tmp = tmp .. string.rep(" ", depth) .. "}"
    elseif type(val) == "number" then
        tmp = tmp .. tostring(val)
    elseif type(val) == "string" then
        tmp = tmp .. string.format("%q", val)
    elseif type(val) == "boolean" then
        tmp = tmp .. (val and "true" or "false")
    else
        tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
    end

    return tmp
end

function p.subCount( frame )
	local qid = frame.args["qid"]
	local e = mw.wikibase.getEntity(qid)
	local chanIds = e:getBestStatements("P2397")
	local firstChanId = chanIds[1]["mainsnak"]["datavalue"]["value"]
	
	local subCounts = e:getBestStatements("P8687")
	local subCount = nil
    for k, v in pairs(subCounts) do
    	if v['qualifiers'] and v['qualifiers']['P2397'] then 
    		local yt_qualifier = v['qualifiers']['P2397']
    		if yt_qualifier[1]['datavalue']['value'] == firstChanId then
    			subCount = serializeTable(v["mainsnak"]["datavalue"]["value"])
    		end
    	end
	end


    return "hello 6 :" ..  subCount
end

return p