Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
params = {
"q": payload,
"format": "json",
"h": 2, # max number of results (hits)
}
r = requests.get(self.api_url, params=params)
if not r.ok:
raise HttpError("Failed request to {}".format(self.api_url))
data = r.json()
try:
results = data["result"]["hits"]["hit"]
except KeyError:
raise NotFoundError("No match")
if len(results) == 1:
return _dblp_to_pybtex(results[0]["info"])
return _dblp_to_pybtex(heuristic_unique_result(results, d)["info"])
# crossref etiquette,
#
headers = {
"User-Agent": "betterbib/{} ({}; mailto:{})".format(
__version__, __website__, __author_email__
)
}
r = requests.get(self.api_url, params=params, headers=headers)
if not r.ok:
raise HttpError("Failed request to {}".format(self.api_url))
results = r.json()["message"]["items"]
if not results:
raise NotFoundError("No match")
if len(results) == 1:
return self._crossref_to_pybtex(results[0])
return self._crossref_to_pybtex(heuristic_unique_result(results, d))
def find_unique(self, entry):
d = pybtex_to_dict(entry)
if "title" not in d and "doi" not in d and "author" not in d:
raise NotFoundError("Not enough input data")
L = []
keys = [
"title",
"journal",
"doi",
"pages",
"year",
"volume",
"number",
"publisher",
]
for key in keys:
try:
L.append(d[key])