Module:ProfitExtractor: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
-- Get the page title from the argument | -- Get the page title from the argument | ||
local page = frame.args[1] | local page = frame.args[1] | ||
-- Get the title object for the page | |||
local pageTitle = mw.title.new(page) | |||
-- Ensure the page exists | |||
if not pageTitle.exists then | |||
return "Page not found" | |||
end | |||
-- Get the content of the page | -- Get the content of the page | ||
local | local pageContent = mw.page.getContent(pageTitle) | ||
-- Ensure page content is available | |||
if not pageContent then | |||
return "Page content is unavailable" | |||
end | |||
-- Search for the profit using a pattern (looking for "Profit" followed by a number) | -- Search for the profit using a pattern (looking for "Profit" followed by a number) |
Revision as of 10:10, 5 May 2025
Documentation for this module may be created at Module:ProfitExtractor/doc
-- Profit extraction module
local p = {}
function p.extractProfit(frame)
-- Get the page title from the argument
local page = frame.args[1]
-- Get the title object for the page
local pageTitle = mw.title.new(page)
-- Ensure the page exists
if not pageTitle.exists then
return "Page not found"
end
-- Get the content of the page
local pageContent = mw.page.getContent(pageTitle)
-- Ensure page content is available
if not pageContent then
return "Page content is unavailable"
end
-- Search for the profit using a pattern (looking for "Profit" followed by a number)
local profit = string.match(pageContent, "Profit%s*:?%s*(%d[%d,]*)")
-- Return the profit value or a default message if not found
return profit or "Profit not found"
end
return p