summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2018-03-24 17:22:29 +0100
committerRobin Krahl <me@robin-krahl.de>2018-03-24 17:22:29 +0100
commit54efba8e3b8fb20e506a31b3b9e452e1eccffe34 (patch)
treefb2d051c1b67139a09ae66d09a266efb24a15e3e
parent64037f9a53928ef3fb8b468d7abc2d15ecd1a28c (diff)
downloadbibtool-54efba8e3b8fb20e506a31b3b9e452e1eccffe34.tar.gz
bibtool-54efba8e3b8fb20e506a31b3b9e452e1eccffe34.tar.bz2
Add --doi option for explicit DOIs
-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))