From 54efba8e3b8fb20e506a31b3b9e452e1eccffe34 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sat, 24 Mar 2018 17:22:29 +0100 Subject: Add --doi option for explicit DOIs --- bibtool/cli.py | 5 +++-- bibtool/extract.py | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bibtool/cli.py b/bibtool/cli.py index 43d6c21..6fe0890 100644 --- a/bibtool/cli.py +++ b/bibtool/cli.py @@ -23,8 +23,9 @@ def cli(): @click.argument('filename', type=TYPE_FILE) @click.option('--directory', type=TYPE_DIR, default=os.getcwd()) @click.option('--delete/--no-delete', default=False) -def _import(filename, directory, delete): - bibtex_data = bibtool.extract.get_bibtex_data(filename) +@click.option('--doi', type=str, default=None) +def _import(filename, directory, delete, doi): + bibtex_data = bibtool.extract.get_bibtex_data(filename, doi) if not bibtex_data.entries: raise Exception('Did not find any Bibtex entry.') diff --git a/bibtool/extract.py b/bibtool/extract.py index 6955dbe..cefbe8f 100644 --- a/bibtool/extract.py +++ b/bibtool/extract.py @@ -42,8 +42,9 @@ def _get_data_for_doi(doi): return bibtexparser.loads(bibtex) -def _handle_pdf(filename): - doi = _extract_doi(filename) +def _handle_pdf(filename, doi): + if not doi: + doi = _extract_doi(filename) if not doi: raise Exception('Could not extract a DOI from the PDF file') @@ -51,8 +52,8 @@ def _handle_pdf(filename): return _get_data_for_doi(doi) -def get_bibtex_data(filename): +def get_bibtex_data(filename, doi): mtype, _ = mimetypes.guess_type(filename) if mtype == 'application/pdf': - return _handle_pdf(filename) + return _handle_pdf(filename, doi) raise Exception('Unsupported file type ' + str(mtype)) -- cgit v1.2.3