Created
March 26, 2012 23:12
-
-
Save msalvadores/2210491 to your computer and use it in GitHub Desktop.
Simple Python Script to Query sparql.bioportal.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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