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
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Profit extraction module
-- ProfitExtractor Module
local p = {}
local p = mw.title.new("Money_making_guide/Killing_Tormented_demons")


function p.extractProfit(frame)
-- Create the result table
    -- Define the page from which to extract the profit
local result = {}
    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")
-- Check if the page object is valid
     local profit = string.match(profitText, "Profit%s*:?%s*(%d[%d,]*)") -- Match a number like 350,168
if not p or not p.exists then
    result.error = "Error: Page not found."
else
    -- Fetch the page content
     local content = p:getContent()


     -- Return the profit value or a fallback message if not found
     -- Check if content is fetched correctly
    return profit or "Profit not found"
    if not content then
        result.error = "Error: No content found on the page."
    else
        -- 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
    end
end
end


return p
return result

Latest revision as of 10:14, 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."
else
    -- 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."
    else
        -- 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
    end
end

return result