Module:SPARQL: Difference between revisions

From TITAF TANGOWIKI
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
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 http = require("socket.http")


local function fetch_url(url)
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)
     local body, code, headers = http.request(url)
     return body
 
     if code == 200 then
        return body
    else
        return "Error: HTTP " .. (code or "unknown")
    end
end
end


return fetch_url("https://www.example.com")
return p

Latest revision as of 22:48, 21 March 2025

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