Module:SPARQL

From TITAF TANGOWIKI
Revision as of 22:48, 21 March 2025 by Donxello (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:SPARQL/doc

package.path = package.path .. ";/usr/local/share/lua/5.1/?.lua"
package.cpath = package.cpath .. ";/usr/local/lib/lua/5.1/?.so"

local http = require("socket.http")  -- Now try to load it


local http = require("socket.http")

local p = {}

function p.fetchData(frame)
    local sparqlQuery = frame.args[1]
    local url = "https://query.wikidata.org/sparql?query=" .. mw.uri.encode(sparqlQuery, "PATH")

    local body, code, headers = http.request(url)

    if code == 200 then
        return body
    else
        return "Error: HTTP " .. (code or "unknown")
    end
end

return p