summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bibtool/cli.py5
-rw-r--r--bibtool/extract.py9
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))