Skip to content

Instantly share code, notes, and snippets.

@msalvadores
Created March 26, 2012 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msalvadores/2210491 to your computer and use it in GitHub Desktop.
Save msalvadores/2210491 to your computer and use it in GitHub Desktop.
Simple Python Script to Query sparql.bioportal.org
import json,urllib2,urllib,traceback, sys
def query(q,apikey,epr,f='application/json'):
try:
params = {'query': q, 'apikey': apikey}
params = urllib.urlencode(params)
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request(epr+'?'+params)
request.add_header('Accept', f)
request.get_method = lambda: 'GET'
url = opener.open(request)
return url.read()
except Exception, e:
traceback.print_exc(file=sys.stdout)
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment