How to use the betterbib.tools.doi_from_url 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
'month': 1,
            },
        persons=pybtex.database.OrderedCaseInsensitiveDict({
            'author': [
                pybtex.database.Person(u'Gaul, Andr\xe9'),
                pybtex.database.Person(u'Gutknecht, Martin H.'),
                pybtex.database.Person(u'Liesen, J\xf6rg'),
                pybtex.database.Person(u'Nabben, Reinhard')
                ]
            }))

    assert betterbib.pybtex_to_bibtex_string(bt, 'key') \
        == betterbib.pybtex_to_bibtex_string(reference, 'key')

    assert betterbib.tools.get_short_doi(
        betterbib.tools.doi_from_url(bt.fields['url'])
        ) == '10/f44kd7'

    return
github nschloe / betterbib / betterbib / cli / dedup_doi.py View on Github external
def main(argv=None):
    parser = _get_parser()
    args = parser.parse_args(argv)

    data = bibtex.Parser().parse_file(args.infile)

    od = data.entries

    # deduplicate
    for key in data.entries:
        if "url" in od[key].fields and "doi" in od[key].fields:
            doi = tools.doi_from_url(od[key].fields["url"])
            if doi == od[key].fields["doi"]:
                # Would be nicer to remove it completely; see
                # .
                if args.keep_doi:
                    od[key].fields["url"] = None
                else:
                    od[key].fields["doi"] = None

    _write(od, args.outfile, "curly")
    return
github nschloe / betterbib / betterbib / adapt_doi_urls.py View on Github external
def _update_doi_url(d, url_from_doi):
    for bib_id in d:
        if "url" in d[bib_id].fields:
            doi = tools.doi_from_url(d[bib_id].fields["url"])
            if doi:
                new_url = url_from_doi(doi)
                if new_url:
                    d[bib_id].fields["url"] = new_url
    return d