Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_request(url, ids, format, style, locale, **kwargs):
type = cn_format_headers[format]
if format == "citeproc-json":
url = "http://api.crossref.org/works/" + ids + "/" + type
else:
if format == "text":
type = type + "; style = " + style + "; locale = " + locale
url = url + "/" + ids
htype = {'Accept': type}
head = dict(make_ua(), **htype)
response = requests.get(url, headers = head, allow_redirects = True, **kwargs)
# Raise an HTTPError if the status code of the response is 4XX or 5XX
response.raise_for_status()
# set encoding
response.encoding = "UTF-8"
return response.text
if works:
res = Request(mailto, ua_string, url, str(ids[i]) + "/works",
query, filter, offset, limit, sample, sort,
order, facet, select, cursor, cursor_max, None,
progress_bar, **kwargs).do_request()
coll.append(res)
else:
if agency:
endpt = url + str(ids[i]) + "/agency"
else:
endpt = url + str(ids[i])
endpt = endpt.strip("/")
try:
r = requests.get(endpt, params = payload, headers = make_ua(mailto, ua_string))
r.raise_for_status()
except requests.exceptions.HTTPError:
if is_json(r):
raise RequestError(r.status_code, parse_json_err(r))
else:
r.raise_for_status()
except requests.exceptions.RequestException as e:
raise e
check_json(r)
js = r.json()
coll.append(js)
if len(coll) == 1:
coll = coll[0]
return coll
def _req(self, payload):
try:
r = requests.get(self._url(), params = payload, headers = make_ua(self.mailto, self.ua_string))
r.raise_for_status()
except requests.exceptions.HTTPError:
try:
f = r.json()
raise RequestError(r.status_code, f['message'][0]['message'])
except:
r.raise_for_status()
except requests.exceptions.RequestException as e:
print(e)
check_json(r)
return r.json()
:param keyc: [String] your API key
See http://labs.crossref.org/openurl/ for more info on this Crossref API service.
Usage::
from habanero import counts
counts.citation_count(doi = "10.1371/journal.pone.0042793")
counts.citation_count(doi = "10.1016/j.fbr.2012.01.001")
# DOI not found
## FIXME
counts.citation_count(doi = "10.1016/j.fbr.2012")
'''
args = {"id": "doi:" + doi, "pid": key, "noredirect": True}
args = dict((k, v) for k, v in args.items() if v)
res = requests.get(url, params = args, headers = make_ua(), **kwargs)
xmldoc = minidom.parseString(res.content)
val = xmldoc.getElementsByTagName('query')[0].attributes['fl_count'].value
return int(str(val))