Module:ProfitExtractor: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
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)
-- Check if the page exists
    -- Get the page title from the argument
if not p then
     local page = frame.args[1]
     return "Error: Page not found."
   
end
    -- Get the title object for the page
 
    local pageTitle = mw.title.new(page)
-- Fetch the page content
   
local content = p:getContent()
    -- Ensure the page exists
    if not pageTitle.exists then
        return "Page not found"
    end


    -- Get the content of the page
-- Check if content is fetched correctly
    local pageContent = mw.page.getContent(pageTitle)
if not content then
   
    return "Error: No content found on the page."
    -- Ensure page content is available
end
    if not pageContent then
        return "Page content is unavailable"
    end


    -- Search for the profit using a pattern (looking for "Profit" followed by a number)
-- Regular expression to extract the profit (assumes profit is in the form "Profit: X")
    local profit = string.match(pageContent, "Profit%s*:?%s*(%d[%d,]*)")
local profit = content:match("Profit: ([%,0-9]+)")


    -- Return the profit value or a default message if not found
-- Check if the profit was found
     return profit or "Profit not found"
if profit then
     return "Profit: " .. profit
else
    return "Error: Profit information not found."
end
end
return p

Revision as of 10:12, 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")

-- Check if the page exists
if not p then
    return "Error: Page not found."
end

-- Fetch the page content
local content = p:getContent()

-- Check if content is fetched correctly
if not content then
    return "Error: No content found on the page."
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
    return "Profit: " .. profit
else
    return "Error: Profit information not found."
end