-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudo_query_helpers.py
26 lines (21 loc) · 1005 Bytes
/
sudo_query_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
from SPARQLWrapper import SPARQLWrapper, JSON
from helpers import log
sparqlQuery = SPARQLWrapper(os.environ.get('MU_SPARQL_ENDPOINT'), returnFormat=JSON)
sparqlQuery.addCustomHttpHeader('mu-auth-sudo', 'true')
sparqlUpdate = SPARQLWrapper(os.environ.get('MU_SPARQL_UPDATEPOINT'), returnFormat=JSON)
sparqlUpdate.method = 'POST'
sparqlUpdate.addCustomHttpHeader('mu-auth-sudo', 'true')
def query(the_query):
"""Execute the given SPARQL query (select/ask/construct)on the triple store and returns the results
in the given returnFormat (JSON by default)."""
log("execute query: \n" + the_query)
sparqlQuery.setQuery(the_query)
return sparqlQuery.query().convert()
def update(the_query):
"""Execute the given update SPARQL query on the triple store,
if the given query is no update query, nothing happens."""
sparqlUpdate.setQuery(the_query)
if sparqlUpdate.isSparqlUpdateRequest():
log("execute query: \n" + the_query)
sparqlUpdate.query()