Module:ProfitExtractor: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
(Created page with "-- Profit extraction module local p = {} function p.extractProfit(frame) -- Define the page from which to extract the profit local page = frame.args[1] -- The page name passed as an argument local profitText = mw.page.getContent(page) -- Get the full content of the page -- Pattern to match the profit number (assuming it's listed with the word "Profit") local profit = string.match(profitText, "Profit%s*:?%s*(%d[%d,]*)") -- Match a number like 350,...")
 
No edit summary
Line 3: Line 3:


function p.extractProfit(frame)
function p.extractProfit(frame)
     -- Define the page from which to extract the profit
     -- Get the page title from the argument
     local page = frame.args[1] -- The page name passed as an argument
     local page = frame.args[1]
    local profitText = mw.page.getContent(page)  -- Get the full content of the page


     -- Pattern to match the profit number (assuming it's listed with the word "Profit")
     -- Get the content of the page
     local profit = string.match(profitText, "Profit%s*:?%s*(%d[%d,]*)")  -- Match a number like 350,168
     local pageTitle = mw.title.new(page)
    local pageContent = pageTitle:getContent()  -- Get page content


     -- Return the profit value or a fallback message if not found
    -- 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"
     return profit or "Profit not found"
end
end


return p
return p

Revision as of 10:09, 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 content of the page
    local pageTitle = mw.title.new(page)
    local pageContent = pageTitle:getContent()  -- Get page content

    -- 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