Module:Cron/alch

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 10:03, 17 October 2024 (Created page with "local exchange = require('Module:Exchange') local p = {} function p.getPages(offset) local dpl_base = [[{{#dpl: |namespace = Exchange |ordermethod = title |format = ,\n@@%%TITLE%%,, |offset = %s }}]] local pages = {} local dpl = string.format(dpl_base, offset) local r = mw.getCurrentFrame():preprocess(dpl) if string.match(r, "Warning: No results.") then return pages end local split = mw.text.gsplit(r, '@@') for line in split do line = mw.text.trim(line) i..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Documentation for this module may be created at Module:Cron/alch/doc

local exchange = require('Module:Exchange')

local p = {}

function p.getPages(offset)
	local dpl_base = [[{{#dpl:
|namespace = Exchange
|ordermethod = title
|format = ,\n@@%%TITLE%%,,
|offset = %s
}}]]
	local pages = {}
	local dpl = string.format(dpl_base, offset)
	local r = mw.getCurrentFrame():preprocess(dpl)
	if string.match(r, "Warning: No results.") then
		return pages
	end
	local split = mw.text.gsplit(r, '@@')
	for line in split do
		line = mw.text.trim(line)
		if line ~= '' then
			local values = mw.text.split(line, '\n|')
			local page = table.remove(values, 1)
			pages[page] = values
		end
	end
	return pages
end

function p.each(page, data)
	local limit = exchange._highalch(page, 1)
	table.insert(data, limit)
end

function p.main(frame)
	local offset = frame.args.offset
	local pages = p.getPages(offset)
	
	for page, data in pairs(pages) do
		p.each(page, data)
		if #data == 0 then
			pages[page] = nil
		end
		if #data == 1 then
			pages[page] = data[1]
		end
	end
	
	local ret = mw.dumpObject(pages):gsub('table#%d+', '')
	return ret
end

return p