Modul:FetchData

A Wikiszótárból, a nyitott szótárból

A modult a Modul:FetchData/doc lapon tudod dokumentálni

local wikidata = require("Module:Wikidata")
local json = require("Module:Json")

local p = {}

function p.fetchData(frame)
    local title = mw.title.getCurrentTitle().text
    local site = mw.site.interwiki("wikipedia")

    -- Check if Wikipedia article exists with the same title
    if site.exists then
        local wikipediaTitle = site.title
        local wdId = wikidata.getID(wikipediaTitle)

        -- If Wikidata ID is found, fetch data
        if wdId then
            local data = wikidata.fetch(wdId)
            if data then
                return json.encode(data)
            else
                return "Error: Unable to fetch data from Wikidata"
            end
        else
            return "Error: Wikipedia article exists but no corresponding Wikidata item found"
        end
    else
        return "Error: Wikipedia article does not exist"
    end
end

return p