Module:ProfitExtractor

From Roat Pkz
Revision as of 10:10, 5 May 2025 by Hefner (talk | contribs)
Jump to navigation Jump to search

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