Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Test2: Difference between revisions

From ProleWiki, the proletarian encyclopedia
m (Using time in seconds of the os to generate more randomness)
m (Refining capture so that it captures more than a single word)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
function splitLines(text)
    local lines = {}
    for line in text:gmatch("[^\r\n]+") do
        table.insert(lines, line)
    end
    return lines
end
local p = {}
local p = {}


function p.randomNumber(frame)
function p.Sitename(frame)
local seed = tostring(os.time()):reverse():sub(1,5)
local extDataTable = mw.ext.externalData.getExternalData(frame.args[1])[1]["__text"]
math.randomseed(seed)
local dataLines = splitLines(extDataTable)
local min = tonumber(frame.args[1]) or 0
local sitename = ''
local max = tonumber(frame.args[2]) or 100
for i,line in ipairs(dataLines) do
return math.random(min, max)
if line:match("og:site_name") then
sitename = line:match('content="([^"]+)"')
break
end
end
return sitename
end
end


return p
return p

Latest revision as of 12:36, 23 April 2024

function splitLines(text)
    local lines = {}
    for line in text:gmatch("[^\r\n]+") do
        table.insert(lines, line)
    end
    return lines
end

local p = {}

function p.Sitename(frame)
	local extDataTable = mw.ext.externalData.getExternalData(frame.args[1])[1]["__text"]
	local dataLines = splitLines(extDataTable)
	local sitename = ''
	for i,line in ipairs(dataLines) do
		if line:match("og:site_name") then
			sitename = line:match('content="([^"]+)"')
			break
		end
	end
	return sitename
end

return p