def query_fundref_api(query, **kwargs): """ Perform a request to the Fundref API. """ sleep(1) req = urllib2.Request("http://api.crossref.org%s?%s" % (query, urllib.urlencode(kwargs)), headers={'content-type': 'application/vnd.crossref-api-message+json; version=1.0'}) res = json_unicode_to_utf8(json.load(CROSSREF_OPENER.open(req))) return res['message']
def query_fundref_api(query, **kwargs): """ Perform a request to the Fundref API. """ sleep(1) req = urllib2.Request( "http://api.crossref.org%s?%s" % (query, urllib.urlencode(kwargs)), headers={ 'content-type': 'application/vnd.crossref-api-message+json; version=1.0' }) res = json_unicode_to_utf8(json.load(CROSSREF_OPENER.open(req))) return res['message']
def solr_get_facets(bitset, solr_url): facet_query_url = "%s/invenio_facets" % solr_url # now use the bitset to fetch the facet data r = urllib2.Request(facet_query_url) data = bitset.fastdump() boundary = mimetools.choose_boundary() # fool solr into thinking we're uploading a file so it will read our data as a stream contents = '--%s\r\n' % boundary contents += 'Content-Disposition: form-data; name="bitset"; filename="bitset"\r\n' contents += 'Content-Type: application/octet-stream\r\n' contents += '\r\n' + data + '\r\n' contents += '--%s--\r\n\r\n' % boundary r.add_data(contents) contenttype = 'multipart/form-data; boundary=%s' % boundary r.add_unredirected_header('Content-Type', contenttype) # post the request and get back the facets as json u = SOLRUTILS_OPENER.open(r) return json.load(u)