How to use the betterbib.errors.HttpError function in betterbib

To help you get started, we’ve selected a few betterbib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nschloe / betterbib / betterbib / sync.py View on Github external
num_success = 0
    with concurrent.futures.ThreadPoolExecutor(max_workers=max_workers) as executor:
        responses = {
            executor.submit(source.find_unique, entry): (bib_id, tools.decode(entry))
            for bib_id, entry in d.items()
        }
        for future in tqdm(
            concurrent.futures.as_completed(responses), total=len(responses)
        ):
            bib_id, entry = responses[future]
            try:
                data = future.result()
            except (errors.NotFoundError, errors.UniqueError):
                pass
            except errors.HttpError as e:
                print(e.args[0])
            else:
                num_success += 1
                d[bib_id] = tools.update(entry, data)

    print("\n\nTotal number of entries: {}".format(len(d)))
    print("Found: {}".format(num_success))
    return d
github nschloe / betterbib / betterbib / crossref.py View on Github external
crossref_types = _bibtex_to_crossref_type(entry.type)
        if crossref_types:
            params["filter"] = ",".join("type:{}".format(ct) for ct in crossref_types)

        # 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))
github nschloe / betterbib / betterbib / dblp.py View on Github external
# kick out empty strings
        L = list(filter(None, L))

        # Simply plug the dict together to a search query. Typical query:
        # ?q=vanroose+schl%C3%B6mer&h=5
        payload = codecs.decode(" ".join(L), "ulatex").replace(" ", "+")

        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"])