How to use the betterbib.errors.UniqueError 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 / test / test_crossref.py View on Github external
source = betterbib.Crossref()

    test_entry = pybtex.database.Entry(
        'article',
        fields={
            # 'title': 'Stratified atmospheric boundary layers',
            'journal': 'Boundary-Layer Meteorology',
            'pages': '375--396',
            },
        persons={'author': [
            pybtex.database.Person('Mahrt'),
            ]}
        )

    # Make sure and exception is thrown when not finding a unique match
    with pytest.raises(betterbib.errors.UniqueError):
        source.find_unique(test_entry)

    return
github nschloe / betterbib / test / test_crossref.py View on Github external
def test_crossref_no_title():
    source = betterbib.Crossref()

    test_entry = pybtex.database.Entry(
        "article",
        fields={
            # 'title': 'Stratified atmospheric boundary layers',
            "journal": "Boundary-Layer Meteorology",
            "pages": "375--396",
        },
        persons={"author": [pybtex.database.Person("Mahrt")]},
    )

    # Make sure and exception is thrown when not finding a unique match
    with pytest.raises(betterbib.errors.UniqueError):
        source.find_unique(test_entry)
github nschloe / betterbib / betterbib / sync.py View on Github external
print()

    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 / tools.py View on Github external
for result in results:
            if "page" in result and result["page"] == d["pages"]:
                return result

    # If that doesn't work, check if the second entry is a JSTOR copy of the original
    # article -- yes, that happens --, and take the first one.
    if (
        "publisher" in results[1]
        and results[1]["publisher"] == "JSTOR"
        and "title" in results[0]
        and "title" in results[1]
        and results[0]["title"][0].lower() == results[1]["title"][0].lower()
    ):
        return results[0]

    raise UniqueError(
        "Could not find a positively unique match. "
        "Got\n\n{}\n\nand\n\n{}\n".format(
            prettyprint_result(results[0]), prettyprint_result(results[1])
        )