Modul:ceribandin/Balyozxane

Documentation for this module may be created at Modul:ceribandin/Balyozxane/belge

local JSON = require("Module:JSON")

local p = {}

function p.getNumberOfPagesInCategory(category)
    local apiUrl = "https://ku.wiktionary.org/w/api.php"
    local params = {
        action = "query",
        list = "categorymembers",
        cmtitle = category,
        cmlimit = 500,
        format = "json"
    }

    local urlEncodedParams = mw.text.encode(JSON.json_fromTable(params))

    local response = mw.text.unstrip(mw.text.unstripNoWiki("[[" .. apiUrl .. "?action=parse&pst=true&text=" .. urlEncodedParams .. "]]"))

    if response then
        local data = JSON.toJSON(response)
        local pageCount = data.query.categorymembers and #data.query.categorymembers or 0
        return "Number of pages in category " .. category .. ": " .. pageCount
    else
        return "Error fetching data from the API"
    end
end

return p