Esempio n. 1
0
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']
Esempio n. 2
0
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']
Esempio n. 3
0
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)
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)
Esempio n. 5
0
 def get_drupal_data():
     data = json.load(urllib2.urlopen(DRUPAL_FEED))
     data = map(lambda x: str(x['name'].encode('utf-8')), data['tags'])
     return json.dumps(data)