Module:Sandbox/User:Alsang/PriceChecker: Difference between revisions
Module:Sandbox/User:Alsang/PriceChecker (edit)
Revision as of 11:03, 4 December 2024
, 4 December 2024no edit summary
No edit summary |
Californ1a (talk | contribs) mNo edit summary |
||
Line 1:
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(",", "")
return value
end
function p.main()
'order = asc'
}
local out = {}
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
if infoboxValue == nil then
▲ for _,item in ipairs(results) do
infoboxValue = 0
elseif type(infoboxValue)=='string' then
table.insert(out,item.Name)▼
infoboxValue = tonumber(cleanNumberString(item.InfoboxValue))
▲ end
local hasMismatch = false
for _, shopValue in ipairs(shopValues) do
if shopValue ~= "N/A" then
-- Compare numeric values
local cleanShopValue = cleanNumberString(shopValue)
local numericShopValue = tonumber(cleanShopValue)
if numericShopValue and numericShopValue ~= infoboxValue then
hasMismatch = true
break
end
end
end
-- Add the item to the output if any shopValue mismatched InfoboxValue
if hasMismatch then
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
|