Editing Module:Sandbox/User:Alsang/PriceChecker
Jump to navigation
Jump to search
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 |
|||
⚫ | |||
local function cleanNumberString(value) |
|||
⚫ | |||
return value:gsub(",", "") |
|||
⚫ | |||
return value |
|||
⚫ | |||
⚫ | |||
function p.main() |
function p.main() |
||
-- Returns only directly needed parameters for the row, |
|||
-- other parameters are determined by subqueries of chained pages |
|||
local query = { |
|||
'[[-Sold item::~*]]', |
|||
'?=Name', |
|||
'?-Sold item.Shop sell price=ShopValue', |
|||
'?Value=InfoboxValue', |
|||
'limit = 10000', |
|||
'order = asc' |
|||
} |
|||
} |
|||
local results = mw.smw.ask(query) |
|||
⚫ | |||
⚫ | |||
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 infoboxValue = item.InfoboxValue |
|||
if infoboxValue == nil then |
|||
⚫ | |||
infoboxValue = 0 |
|||
⚫ | |||
⚫ | |||
local s = item.ShopValue |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if i==tonumber(s) or not(tonumber(s)) then |
|||
add = false |
|||
end |
end |
||
local hasMismatch = false |
|||
⚫ | |||
⚫ | |||
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 |
|||
⚫ | |||
local cleanShopValue = cleanNumberString(shopValue) |
|||
end |
|||
local numericShopValue = tonumber(cleanShopValue) |
|||
end |
|||
if numericShopValue and numericShopValue ~= infoboxValue then |
|||
if add then |
|||
hasMismatch = true |
|||
⚫ | |||
break |
|||
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 |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
-- Format the output to display each item's details |
|||
local output = {} |
|||
⚫ | |||
table.insert(output, mw.text.jsonEncode(item)) -- Convert each item to a JSON string for display |
|||
⚫ | |||
return table.concat(output, '<br>') -- Concatenate the JSON representations with a line break |
|||
end |
end |
||