Module:ProfitExtractor: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
-- ProfitExtractor Module | -- ProfitExtractor Module | ||
local p = mw.title.new("Money_making_guide/Killing_Tormented_demons") | local p = mw.title.new("Money_making_guide/Killing_Tormented_demons") | ||
-- Create the result table | |||
local result = {} | |||
-- Check if the page object is valid | -- Check if the page object is valid | ||
if not p or not p.exists then | if not p or not p.exists then | ||
result.error = "Error: Page not found." | |||
return result | |||
end | end | ||
Line 12: | Line 16: | ||
-- Check if content is fetched correctly | -- Check if content is fetched correctly | ||
if not content then | if not content then | ||
result.error = "Error: No content found on the page." | |||
return result | |||
end | end | ||
Line 20: | Line 25: | ||
-- Check if the profit was found | -- Check if the profit was found | ||
if profit then | if profit then | ||
result.profit = profit | |||
else | else | ||
result.error = "Error: Profit information not found." | |||
end | end | ||
return result |
Revision as of 10:13, 5 May 2025
Documentation for this module may be created at Module:ProfitExtractor/doc
-- ProfitExtractor Module
local p = mw.title.new("Money_making_guide/Killing_Tormented_demons")
-- Create the result table
local result = {}
-- Check if the page object is valid
if not p or not p.exists then
result.error = "Error: Page not found."
return result
end
-- Fetch the page content
local content = p:getContent()
-- Check if content is fetched correctly
if not content then
result.error = "Error: No content found on the page."
return result
end
-- Regular expression to extract the profit (assumes profit is in the form "Profit: X")
local profit = content:match("Profit: ([%,0-9]+)")
-- Check if the profit was found
if profit then
result.profit = profit
else
result.error = "Error: Profit information not found."
end
return result