Editing Module:Sandbox/User:Alsang/PriceChecker

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
local p = {}
local p = {}


-- Utility function to clean up number strings by removing commas
-- non dynamic module, no inputs
local function cleanNumberString(value)
if type(value) == "string" then
return value:gsub(",", "")
end
return value
end

-- Non-dynamic module, no inputs
function p.main()
function p.main()
-- returns only directly needed parameter needed for the row,
-- Returns only directly needed parameters for the row,
-- other parameters are determined by subqueries of chained pages
-- other parameters are determined by subqueries of chained pages
local query = {
local query = {
'[[-Sold item.Shop sell price::+]]',
'[[-Sold item::~*]]',
'?=Name',
'?=Name',
'?-Sold item.Shop sell price=ShopValue',
'?-Sold item.Shop sell price=ShopValue',
'?Value=InfoboxValue',
'?Value=InfoboxValue',
'limit = 500'
'limit = 10000',
'order = asc'
}
}


local results = mw.smw.ask(query)
local results = mw.smw.ask(query)

local out = {}
for _, item in ipairs(results) do
local shopValues = item.ShopValue -- Could be an array or a single value
if shopValues ~= nil then
if type(shopValues) == "string" then
shopValues = { shopValues } -- Normalize to a table for consistency
end
local out = {'List of items:'}
local infoboxValue = item.InfoboxValue
if infoboxValue == nil then
for _,item in ipairs(results) do
infoboxValue = 0
local i = tonumber(item.InfoboxValue)
elseif type(infoboxValue)=='string' then
local s = item.ShopValue
infoboxValue = tonumber(cleanNumberString(item.InfoboxValue))
local add = true
if type(s)=='string' then
if i==tonumber(s) or not(tonumber(s)) then
add = false
end
end
local hasMismatch = false
elseif type(s)=='table' then
for _,shop in ipairs(s) do
for _, shopValue in ipairs(shopValues) do
if i==tonumber(shop) or not(tonumber(shop)) then
if shopValue ~= "N/A" then
add = false
-- Compare numeric values
end
local cleanShopValue = cleanNumberString(shopValue)
end
local numericShopValue = tonumber(cleanShopValue)
end
if numericShopValue and numericShopValue ~= infoboxValue then
if add then
hasMismatch = true
table.insert(out,item.Name)
break
end
end
end
end
table.insert(out,'End of List')
end
return table.concat(out, '<br>')
-- Add the item to the output if any shopValue mismatched InfoboxValue
if hasMismatch then
table.insert(out, item)
end
end
end

-- Format the output to display each item's details
local output = {}
for _, item in ipairs(out) do
table.insert(output, mw.text.jsonEncode(item)) -- Convert each item to a JSON string for display
end

return table.concat(output, '<br>') -- Concatenate the JSON representations with a line break
end
end


Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see Brighter Shores:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

This page is a member of a hidden category: