├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── MANIFEST.in ├── README ├── README.md ├── docs ├── Makefile └── source │ ├── conf.py │ ├── doi2bib.rst │ ├── examples.rst │ ├── index.rst │ └── install.rst ├── doi2bib ├── __init__.py ├── bin │ └── doi2bib └── crossref.py ├── readthedocs.yml ├── requirements.txt ├── requirements_docs.txt ├── setup.cfg └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | # Byte-compiled / optimized / DLL files 3 | __pycache__/ 4 | *.py[cod] 5 | *$py.class 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | .Python 12 | env/ 13 | develop-eggs/ 14 | eggs/ 15 | doi2bib.egg-info/ 16 | dist/ 17 | build/ 18 | downloads/ 19 | eggs/ 20 | .eggs/ 21 | lib/ 22 | lib64/ 23 | parts/ 24 | sdist/ 25 | var/ 26 | wheels/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | .hypothesis/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | local_settings.py 59 | 60 | # Flask stuff: 61 | instance/ 62 | .webassets-cache 63 | 64 | # Scrapy stuff: 65 | .scrapy 66 | 67 | # Sphinx documentation 68 | docs/_build/ 69 | 70 | # PyBuilder 71 | target/ 72 | 73 | # Jupyter Notebook 74 | .ipynb_checkpoints 75 | 76 | # pyenv 77 | .python-version 78 | 79 | # celery beat schedule file 80 | celerybeat-schedule 81 | 82 | # SageMath parsed files 83 | *.sage.py 84 | 85 | # dotenv 86 | .env 87 | 88 | # virtualenv 89 | .venv 90 | venv/ 91 | ENV/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.linting.pylintEnabled": false, 3 | "python.linting.pycodestyleEnabled": false, 4 | "python.linting.enabled": true, 5 | "python.linting.flake8Enabled": true 6 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 doi2bib 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | 2 | include doi2bib README 3 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Description 2 | =========== 3 | 4 | doi2bib is a module of 5 | `bibcure `__\ and 6 | `scihub2pdf `__ 7 | 8 | Install 9 | ======= 10 | 11 | :: 12 | 13 | $ sudo pip install doi2bib 14 | 15 | or if you want the full version 16 | 17 | :: 18 | 19 | $ sudo pip install bibcure 20 | 21 | Features and how to use 22 | ======================= 23 | 24 | Given a DOI number... 25 | 26 | :: 27 | 28 | $ doi2bib 10.1038/s41524-017-0032-0 29 | 30 | - get bib item given a doi(requires internet connection) 31 | 32 | You can easily append a bib into a bibfile, just do 33 | 34 | :: 35 | 36 | $ doi2bib 10.1038/s41524-017-0032-0 >> file.bib 37 | 38 | You also can generate a bibtex from a txt file containing a list of DOIs 39 | 40 | :: 41 | 42 | $ doi2bib --input file_with_dois.txt --output refs.bib 43 | 44 | bibcure 45 | ------- 46 | 47 | Given a bib file... 48 | 49 | :: 50 | 51 | $ bibcure -i input.bib -o output.bib 52 | 53 | - check sure the Arxiv items have been published, then update 54 | them(requires internet connection) 55 | 56 | - complete all fields(url, journal, etc) of all bib items using DOI 57 | number(requires internet connection) 58 | 59 | - find and create DOI number associated with each bib item which has 60 | not DOI field(requires internet connection) 61 | 62 | - abbreviate jorunals names 63 | 64 | title2bib 65 | --------- 66 | 67 | Given a title... 68 | 69 | :: 70 | 71 | $ title2bib An useful paper 72 | 73 | - search papers related and return a bib for the selected 74 | paper(requires internet connection) 75 | 76 | You can easily append a bib into a bibfile, just do 77 | 78 | :: 79 | 80 | $ title2bib An useful paper --first >> file.bib 81 | 82 | You also can generate a bibtex from a txt file containing a list of 83 | "titles" 84 | 85 | :: 86 | 87 | $ title2bib --input file_with_titles.txt --output refs.bib --first 88 | 89 | arxivcheck 90 | ---------- 91 | 92 | Given a arxiv id... 93 | 94 | :: 95 | 96 | $ arxivcheck 1601.02785 97 | 98 | - check if has been published, and then returns the updated bib 99 | (requires internet connection) 100 | 101 | Given a title... 102 | 103 | :: 104 | 105 | $ arxivcheck --title An useful paper published on arxiv 106 | 107 | search papers related and return a bib the first item. You can easily 108 | append a bib into a bibfile, just do 109 | 110 | :: 111 | 112 | $ arxivcheck --title An useful paper published on arxiv >> file.bib 113 | 114 | You also can interact with results, just pass --ask parameter 115 | 116 | :: 117 | 118 | $ arxivcheck --ask --title An useful paper published on arxiv 119 | 120 | scihub2pdf 121 | ========== 122 | 123 | Given a bibtex file 124 | 125 | :: 126 | 127 | $ scihub2pdf -i input.bib 128 | 129 | Given a DOI number... 130 | 131 | :: 132 | 133 | $ scihub2pdf 10.1038/s41524-017-0032-0 134 | 135 | Given a title... 136 | 137 | :: 138 | 139 | $ scihub2bib --title An useful paper 140 | 141 | Location folder as argument 142 | 143 | :: 144 | 145 | $ scihub2pdf -i input.bib -l somefoler/ 146 | 147 | Use libgen instead sci-hub 148 | 149 | :: 150 | 151 | $ scihub2pdf -i input.bib --uselibgen 152 | 153 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | doi2bib is a module of [bibcure](https://github.com/bibcure/bibcure)and [scihub2pdf](https://github.com/bibcure/scihub2pdf) 3 | ![](https://raw.githubusercontent.com/bibcure/logo/master/gifs/doi2bib.gif) 4 | 5 | # Install 6 | 7 | ``` 8 | $ sudo python /usr/bin/pip install doi2bib 9 | ``` 10 | or if you want the full version 11 | 12 | ``` 13 | $ sudo python /usr/bin/pip install bibcure 14 | ``` 15 | # Features and how to use 16 | 17 | 18 | Given a DOI number... 19 | 20 | ``` 21 | $ doi2bib 10.1038/s41524-017-0032-0 22 | ``` 23 | 24 | * get bib item given a doi(requires 25 | internet connection) 26 | 27 | You can easily append 28 | a bib into a bibfile, just do 29 | 30 | ``` 31 | $ doi2bib 10.1038/s41524-017-0032-0 >> file.bib 32 | ``` 33 | 34 | You also can generate a bibtex from a txt file containing a list of DOIs 35 | 36 | ``` 37 | $ doi2bib --input file_with_dois.txt --output refs.bib 38 | ``` 39 | 40 | ## bibcure 41 | 42 | Given a bib file... 43 | 44 | ``` 45 | $ bibcure -i input.bib -o output.bib 46 | ``` 47 | 48 | * check sure the Arxiv items have been published, then update them(requires 49 | internet connection) 50 | 51 | * complete all fields(url, journal, etc) of all bib items using DOI number(requires 52 | internet connection) 53 | 54 | * find and create DOI number associated with each bib item which has not 55 | DOI field(requires 56 | internet connection) 57 | 58 | * abbreviate jorunals names 59 | 60 | 61 | ## title2bib 62 | 63 | Given a title... 64 | 65 | ``` 66 | $ title2bib An useful paper 67 | ``` 68 | 69 | * search papers related and return a bib for the selected paper(requires 70 | internet connection) 71 | 72 | You can easily append 73 | a bib into a bibfile, just do 74 | 75 | ``` 76 | $ title2bib An useful paper --first >> file.bib 77 | ``` 78 | 79 | You also can generate a bibtex from a txt file containing a list of "titles" 80 | 81 | ``` 82 | $ title2bib --input file_with_titles.txt --output refs.bib --first 83 | ``` 84 | 85 | ## arxivcheck 86 | 87 | Given a arxiv id... 88 | 89 | ``` 90 | $ arxivcheck 1601.02785 91 | ``` 92 | 93 | * check if has been published, and then returns the updated bib (requires internet connection) 94 | 95 | Given a title... 96 | 97 | ``` 98 | $ arxivcheck --title An useful paper published on arxiv 99 | ``` 100 | 101 | search papers related and return a bib the first item. 102 | You can easily append a bib into a bibfile, just do 103 | 104 | ``` 105 | $ arxivcheck --title An useful paper published on arxiv >> file.bib 106 | ``` 107 | 108 | You also can interact with results, just pass --ask parameter 109 | 110 | ``` 111 | $ arxivcheck --ask --title An useful paper published on arxiv 112 | ``` 113 | 114 | # scihub2pdf 115 | 116 | Given a bibtex file 117 | 118 | ``` 119 | $ scihub2pdf -i input.bib 120 | ``` 121 | 122 | Given a DOI number... 123 | 124 | ``` 125 | $ scihub2pdf 10.1038/s41524-017-0032-0 126 | ``` 127 | 128 | Given a title... 129 | 130 | ``` 131 | $ scihub2bib --title An useful paper 132 | ``` 133 | 134 | Location folder as argument 135 | 136 | ``` 137 | $ scihub2pdf -i input.bib -l somefoler/ 138 | ``` 139 | 140 | Use libgen instead sci-hub 141 | 142 | ``` 143 | $ scihub2pdf -i input.bib --uselibgen 144 | ``` 145 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = source 8 | BUILDDIR = build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # 3 | # Configuration file for the Sphinx documentation builder. 4 | # 5 | # This file does only contain a selection of the most common options. For a 6 | # full list see the documentation: 7 | # http://www.sphinx-doc.org/en/master/config 8 | 9 | # -- Path setup -------------------------------------------------------------- 10 | 11 | # If extensions (or modules to document with autodoc) are in another directory, 12 | # add these directories to sys.path here. If the directory is relative to the 13 | # documentation root, use os.path.abspath to make it absolute, like shown here. 14 | # 15 | import os 16 | import sys 17 | sys.path.insert(0, os.path.abspath('../..')) 18 | sys.path.insert(0, os.path.abspath('..')) 19 | sys.setrecursionlimit(1500) 20 | 21 | # -- Project information ----------------------------------------------------- 22 | 23 | project = 'doi2bib' 24 | copyright = '2019, Bruno Messias' 25 | author = 'Bruno Messias' 26 | 27 | # The short X.Y version 28 | version = '' 29 | # The full version, including alpha/beta/rc tags 30 | release = '1.0.0' 31 | 32 | 33 | # -- General configuration --------------------------------------------------- 34 | 35 | # If your documentation needs a minimal Sphinx version, state it here. 36 | # 37 | # needs_sphinx = '1.0' 38 | 39 | # Add any Sphinx extension module names here, as strings. They can be 40 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 41 | # ones. 42 | extensions = [ 43 | 'sphinx.ext.autodoc', 44 | 'sphinx.ext.doctest', 45 | 'sphinx.ext.intersphinx', 46 | 'sphinx.ext.todo', 47 | 'sphinx.ext.mathjax', 48 | 'sphinx.ext.ifconfig', 49 | 'sphinx.ext.viewcode', 50 | 'sphinx.ext.githubpages', 51 | 'sphinxcontrib.napoleon', 52 | ] 53 | 54 | # Add any paths that contain templates here, relative to this directory. 55 | templates_path = ['_templates'] 56 | 57 | # The suffix(es) of source filenames. 58 | # You can specify multiple suffix as a list of string: 59 | # 60 | # source_suffix = ['.rst', '.md'] 61 | source_suffix = '.rst' 62 | 63 | # The master toctree document. 64 | master_doc = 'index' 65 | 66 | # The language for content autogenerated by Sphinx. Refer to documentation 67 | # for a list of supported languages. 68 | # 69 | # This is also used if you do content translation via gettext catalogs. 70 | # Usually you set "language" from the command line for these cases. 71 | language = None 72 | 73 | # List of patterns, relative to source directory, that match files and 74 | # directories to ignore when looking for source files. 75 | # This pattern also affects html_static_path and html_extra_path. 76 | exclude_patterns = [] 77 | 78 | # The name of the Pygments (syntax highlighting) style to use. 79 | pygments_style = None 80 | 81 | 82 | # -- Options for HTML output ------------------------------------------------- 83 | 84 | # The theme to use for HTML and HTML Help pages. See the documentation for 85 | # a list of builtin themes. 86 | # 87 | html_theme = 'sphinx_rtd_theme' 88 | 89 | # Theme options are theme-specific and customize the look and feel of a theme 90 | # further. For a list of options available for each theme, see the 91 | # documentation. 92 | # 93 | # html_theme_options = {} 94 | 95 | # Add any paths that contain custom static files (such as style sheets) here, 96 | # relative to this directory. They are copied after the builtin static files, 97 | # so a file named "default.css" will overwrite the builtin "default.css". 98 | html_static_path = ['_static'] 99 | 100 | # Custom sidebar templates, must be a dictionary that maps document names 101 | # to template names. 102 | # 103 | # The default sidebars (for documents that don't match any pattern) are 104 | # defined by theme itself. Builtin themes are using these templates by 105 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html', 106 | # 'searchbox.html']``. 107 | # 108 | # html_sidebars = {} 109 | 110 | 111 | # -- Options for HTMLHelp output --------------------------------------------- 112 | 113 | # Output file base name for HTML help builder. 114 | htmlhelp_basename = 'doi2bibdoc' 115 | 116 | 117 | # -- Options for LaTeX output ------------------------------------------------ 118 | 119 | latex_elements = { 120 | # The paper size ('letterpaper' or 'a4paper'). 121 | # 122 | # 'papersize': 'letterpaper', 123 | 124 | # The font size ('10pt', '11pt' or '12pt'). 125 | # 126 | # 'pointsize': '10pt', 127 | 128 | # Additional stuff for the LaTeX preamble. 129 | # 130 | # 'preamble': '', 131 | 132 | # Latex figure (float) alignment 133 | # 134 | # 'figure_align': 'htbp', 135 | } 136 | 137 | # Grouping the document tree into LaTeX files. List of tuples 138 | # (source start file, target name, title, 139 | # author, documentclass [howto, manual, or own class]). 140 | latex_documents = [ 141 | (master_doc, 'doi2bib.tex', 'doi2bib Documentation', 142 | 'Bruno Messias', 'manual'), 143 | ] 144 | 145 | 146 | # -- Options for manual page output ------------------------------------------ 147 | 148 | # One entry per manual page. List of tuples 149 | # (source start file, name, description, authors, manual section). 150 | man_pages = [ 151 | (master_doc, 'doi2bib', 'doi2bib Documentation', 152 | [author], 1) 153 | ] 154 | 155 | 156 | # -- Options for Texinfo output ---------------------------------------------- 157 | 158 | # Grouping the document tree into Texinfo files. List of tuples 159 | # (source start file, target name, title, author, 160 | # dir menu entry, description, category) 161 | texinfo_documents = [ 162 | (master_doc, 'doi2bib', 'doi2bib Documentation', 163 | author, 'doi2bib', 'One line description of project.', 164 | 'Miscellaneous'), 165 | ] 166 | 167 | 168 | # -- Options for Epub output ------------------------------------------------- 169 | 170 | # Bibliographic Dublin Core info. 171 | epub_title = project 172 | 173 | # The unique identifier of the text. This can be a ISBN number 174 | # or the project homepage. 175 | # 176 | # epub_identifier = '' 177 | 178 | # A unique identification for the text. 179 | # 180 | # epub_uid = '' 181 | 182 | # A list of files that should not be packed into the epub file. 183 | epub_exclude_files = ['search.html'] 184 | 185 | 186 | # -- Extension configuration ------------------------------------------------- 187 | 188 | # -- Options for intersphinx extension --------------------------------------- 189 | 190 | # Example configuration for intersphinx: refer to the Python standard library. 191 | intersphinx_mapping = {'https://docs.python.org/': None} 192 | 193 | # -- Options for todo extension ---------------------------------------------- 194 | 195 | # If true, `todo` and `todoList` produce output, else they produce nothing. 196 | todo_include_todos = True 197 | -------------------------------------------------------------------------------- /docs/source/doi2bib.rst: -------------------------------------------------------------------------------- 1 | ========== 2 | doi2bib 3 | ========== 4 | .. automodule:: doi2bib.crossref 5 | :members: -------------------------------------------------------------------------------- /docs/source/examples.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Examples 3 | ======== 4 | 5 | 6 | Given a DOI number... 7 | --------------------- 8 | 9 | 10 | .. code-block:: bash 11 | 12 | $ doi2bib 10.1038/s41524-017-0032-0 13 | 14 | You can easily append a bib into a bibfile, just do 15 | 16 | 17 | .. code-block:: bash 18 | 19 | $ doi2bib 10.1038/s41524-017-0032-0 >> file.bib 20 | 21 | You also can generate a bibtex from a txt file containing a list of DOIs 22 | 23 | .. code-block:: bash 24 | 25 | $ doi2bib --input file_with_dois.txt --output refs.bib -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to doi2bib's documentation! 2 | ====================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 3 6 | :caption: Contents: 7 | 8 | install 9 | doi2bib 10 | examples 11 | 12 | 13 | 14 | Indices and tables 15 | ================== 16 | 17 | * :ref:`genindex` 18 | * :ref:`modindex` 19 | * :ref:`search` 20 | -------------------------------------------------------------------------------- /docs/source/install.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Install 3 | ======= 4 | 5 | .. code-block:: bash 6 | 7 | pip install doi2bib -------------------------------------------------------------------------------- /doi2bib/__init__.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.4.0" 2 | __license__ = "MIT" 3 | __author__ = "Bruno Messias" 4 | __author_email__ = "messias.physics@gmail.com" 5 | -------------------------------------------------------------------------------- /doi2bib/bin/doi2bib: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | from __future__ import unicode_literals, print_function, absolute_import 3 | import argparse 4 | import textwrap 5 | from doi2bib.crossref import get_bib_from_doi 6 | import io 7 | 8 | 9 | def save_output_bibs(bibs, output_file): 10 | try: 11 | with io.open(output_file, 'w', encoding="utf-8") as bibfile: 12 | for bib in bibs: 13 | bibfile.write("{}\n".format(bib)) 14 | 15 | except TypeError: 16 | print("Can't save in output file\n") 17 | print(bibs) 18 | 19 | 20 | def main(): 21 | parser = argparse.ArgumentParser( 22 | prog="doi2bib", 23 | formatter_class=argparse.RawDescriptionHelpFormatter, 24 | description=textwrap.dedent('''\ 25 | Convert a list of DOIs in a bibfile. 26 | You also can convert a simple DOI, like: 27 | $ doi2bib 10.1063/1.3149495 28 | ----------------------------------------------------- 29 | @author: Bruno Messias 30 | @email: messias.physics@gmail.com 31 | @telegram: @brunomessias 32 | @github: https://github.com/bibcure/doi2bib 33 | ''') 34 | ) 35 | 36 | parser.add_argument( 37 | "--input", "-i", 38 | type=argparse.FileType("r"), 39 | help="input file" 40 | ) 41 | parser.add_argument( 42 | "--output", "-o", 43 | help="bibtex output file") 44 | 45 | parser.add_argument( 46 | "--abstract", 47 | action='store_true', 48 | help="try to import the abstract info") 49 | 50 | args = parser.parse_known_args() 51 | inlinedoi = len(args[1]) > 0 52 | if inlinedoi: 53 | dois = [" ".join(args[1])] 54 | else: 55 | dois = args[0].input.read() 56 | dois = filter(lambda title: title != "", dois.split("\n")) 57 | bibs = [] 58 | for doi in dois: 59 | found, bib = get_bib_from_doi(doi, add_abstract=args[0].abstract) 60 | if found: 61 | bibs.append(bib) 62 | 63 | if len(bibs) > 0: 64 | if inlinedoi: 65 | print("\n\n") 66 | print(bibs[0]) 67 | else: 68 | save_output_bibs(bibs, args[0].output) 69 | 70 | 71 | if __name__ == "__main__": 72 | main() 73 | -------------------------------------------------------------------------------- /doi2bib/crossref.py: -------------------------------------------------------------------------------- 1 | """ 2 | crossref integration 3 | =========================== 4 | The core module 5 | """ 6 | 7 | from __future__ import unicode_literals, print_function, absolute_import 8 | from builtins import str 9 | import requests 10 | import bibtexparser 11 | import re 12 | 13 | bare_url = "http://api.crossref.org/" 14 | 15 | 16 | def get_bib(doi): 17 | """ 18 | Parameters 19 | ---------- 20 | 21 | doi: str 22 | 23 | Returns 24 | ------- 25 | 26 | found: bool 27 | bib: str 28 | """ 29 | url = "{}works/{}/transform/application/x-bibtex" 30 | url = url.format(bare_url, doi) 31 | r = requests.get(url) 32 | found = False if r.status_code != 200 else True 33 | bib = r.content 34 | bib = str(bib, "utf-8") 35 | 36 | return found, bib 37 | 38 | 39 | def get_json(doi): 40 | """ 41 | Parameters 42 | ---------- 43 | doi: str 44 | 45 | Returns 46 | ------- 47 | 48 | found: bool 49 | item: dict 50 | Response from crossref 51 | """ 52 | 53 | url = "{}works/{}" 54 | url = url.format(bare_url, doi) 55 | r = requests.get(url) 56 | found = False if r.status_code != 200 else True 57 | item = r.json() 58 | 59 | return found, item 60 | 61 | 62 | def get_bib_from_doi(doi, abbrev_journal=True, add_abstract=False): 63 | """ 64 | Parameters 65 | ---------- 66 | 67 | doi: str 68 | abbrev_journal: bool 69 | If True try to abbreviate the journal name 70 | Returns 71 | ------- 72 | 73 | found: bool 74 | bib: str 75 | The bibtex string 76 | """ 77 | found, bib = get_bib(doi) 78 | if found and abbrev_journal: 79 | 80 | found, item = get_json(doi) 81 | if found: 82 | abbreviated_journal = item["message"]["short-container-title"] 83 | if add_abstract and "abstract" in item["message"].keys(): 84 | abstract = item["message"]["abstract"] 85 | bi = bibtexparser.loads(bib) 86 | bi.entries[0]["abstract"] = abstract 87 | bib = bibtexparser.dumps(bi) 88 | 89 | if len(abbreviated_journal) > 0: 90 | abbreviated_journal = abbreviated_journal[0].strip() 91 | bib = re.sub( 92 | r"journal = \{[^>]*?\}", 93 | "journal = {" + abbreviated_journal + "}", 94 | bib) 95 | 96 | return found, bib 97 | -------------------------------------------------------------------------------- /readthedocs.yml: -------------------------------------------------------------------------------- 1 | build: 2 | image: latest 3 | 4 | python: 5 | version: 3.6 6 | requirements_file: requirements_docs.txt 7 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | bibtexparser 2 | future 3 | 4 | -------------------------------------------------------------------------------- /requirements_docs.txt: -------------------------------------------------------------------------------- 1 | sphinx-gallery 2 | sphinxcontrib-napoleon 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | description-file = README 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | readme = open('README', 'r') 4 | README_TEXT = readme.read() 5 | readme.close() 6 | 7 | setup( 8 | name="doi2bib", 9 | version="0.4.0", 10 | packages=find_packages(exclude=["build", ]), 11 | scripts=["doi2bib/bin/doi2bib"], 12 | long_description=README_TEXT, 13 | install_requires=["requests", "future", "bibtexparser"], 14 | include_package_data=True, 15 | license="MIT", 16 | description="Generate a bibtex given a doi", 17 | author="Bruno Messias", 18 | author_email="messias.physics@gmail.com", 19 | download_url="https://github.com/bibcure/doi2bib/archive/0.4.0.tar.gz", 20 | keywords=["bibtex", "science", "scientific-journals"], 21 | 22 | classifiers=[ 23 | "Development Status :: 4 - Beta", 24 | "License :: OSI Approved :: MIT License", 25 | "Intended Audience :: Science/Research", 26 | "Programming Language :: Python", 27 | "Topic :: Text Processing :: Markup :: LaTeX", 28 | ], 29 | url="https://github.com/bibcure/doi2bib" 30 | ) 31 | --------------------------------------------------------------------------------