Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
[![DOI](https://zenodo.org/badge/67431697.svg)](https://zenodo.org/badge/latestdoi/67431697)

# doi2bib and friends

This repository provides scripts for converting from either [Digital Object Identifier (DOI)](https://www.doi.org) or [Uniform Resource Locator (URL)](https://en.wikipedia.org/wiki/URL) to [BibTeX](http://www.bibtex.org), or from DOI to plain text.

<p align="center">
<img alt="ASCII video" src="cast.svg">
</p>

## doi2bib
TODO: support storing to the clipboard automatically.
TODO: add the surname of the first author automatically if not given (if only the year is shown as id when retrieved)

Convert [Digital Object Identifier (DOI)](https://www.doi.org) to
[BibTeX](http://www.bibtex.org) using
[crosscite.org](https://citation.crosscite.org/).
DOIs are received and the corresponding BibTeX entries are output.
# Bibliography in your command-line

Inspired by <https://gist.github.com/mlund/4609288> and
<http://www.doi2bib.org/>.
This repository provides scripts for converting from either [Digital Object Identifier (DOI)](https://www.doi.org) or [Uniform Resource Locator (URL)](https://en.wikipedia.org/wiki/URL) to [BibTeX](http://www.bibtex.org), or from DOI to plain text.

## `doi2bib`

**October 16, 2017**: <http://www.doi2bib.org/> seems not to be working
any more.
Convert [Digital Object Identifier (DOI)](https://www.doi.org) to [BibTeX](http://www.bibtex.org) using [crosscite.org](https://citation.crosscite.org/).
DOIs are received and the corresponding BibTeX entries are output.
(Inspired by <https://gist.github.com/mlund/4609288> and <http://www.doi2bib.org/>.)

## doi2text
## `doi2text`

Convert [Digital Object Identifier (DOI)](https://www.doi.org) to plain text
using [crosscite.org](https://citation.crosscite.org/). DOIs are received and
the corresponding text entries are output. In theory, all the styles
available at <https://github.com/citation-style-language/styles> can be used.
Convert [Digital Object Identifier (DOI)](https://www.doi.org) to plain text using [crosscite.org](https://citation.crosscite.org/).
DOIs are received and the corresponding text entries are output. In theory, all the styles available at <https://github.com/citation-style-language/styles> can be used.

## url2bib
## `url2bib`

Convert [Uniform Resource Locator (URL)](https://en.wikipedia.org/wiki/URL) to
[BibTeX](http://www.bibtex.org) using pure
[Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell)).
Convert [Uniform Resource Locator (URL)](https://en.wikipedia.org/wiki/URL) to [BibTeX](http://www.bibtex.org) using pure [Bash](<https://en.wikipedia.org/wiki/Bash_(Unix_shell)>).
URLs are received and the corresponding BibTeX entries are output.
(This is made to be used exactly as one would use `doi2bib`.)

(This is made to be used exactly as one would use doi2bib.)
This requires `gawk` (`sudo apt install gawk`).

## Dependencies

`doi2bib` requires [curl](https://curl.haxx.se/):

$ sudo apt install curl

You will also need `make` to install:

$ sudo apt install make

## Installation

After downloading the tarball and using `cd` to go where the files are, simply do a `sudo make install` and everything will be installed.
By default, it will install in `/usr/local/bin/`.

## Usage

$ doi2bib 10.1021/acs.jpcc.8b06244 10.1021/acscatal.9b00210
$ doi2bib 10.1021/acs.jpcc.8b06244 10.1021/acscatal.9b00210
@article{Schneider_2018,
title={How Do Secondary Phosphine Oxides Interact with Silver Nanoclusters? Insights from Computation},
volume={122},
Expand Down Expand Up @@ -92,3 +96,7 @@ After downloading the tarball and using `cd` to go where the files are, simply d
howpublished = {\url{https://github.com/schneiderfelipe/doi2bib}},
note = {Accessed: 2020-01-27}
}

## Citing doi2bib

If you use doi2bib in your research, please cite it.
17 changes: 17 additions & 0 deletions src/bibmagic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python

import sys
import bibtexparser as btp
from bibtexparser.bparser import BibTexParser
from bibtexparser.customization import homogenize_latex_encoding

with open(sys.argv[1]) as bib_file:
parser = BibTexParser()
# parser.customization = homogenize_latex_encoding
bib_db = btp.load(bib_file, parser=parser)

if len(sys.argv) > 2:
with open(sys.argv[2], 'w') as bib_file:
btp.dump(bib_db, bib_file)
else:
print(btp.dumps(bib_db))
5 changes: 4 additions & 1 deletion src/doi2bib
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ for doi in "$@"; do
# we do some encoding as needed.
doi=${doi//+/%2B}
http_headers="Accept: text/bibliography; style=bibtex"

echo "$http_headers"
echo

# we retrieve the data from https://doi.org/
curl -s -LH "$http_headers" "https://doi.org/${doi}" | \
curl -LH "$http_headers" "https://doi.org/${doi}" | \
sed -e $'s/^ *//' \
-e $'s/}, /},\\\n /g' \
-e $'s/, /,\\\n /1' \
Expand Down
14 changes: 9 additions & 5 deletions src/doi2text
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#? -v show version
#? -s set ciation style from the ones given in
#? <https://github.com/citation-style-language/styles> (this is
#? "chicago-author-date" by default, see examples below)
#? "american-chemical-society" by default, see examples below)
#? -S list all available citation styles and quit
#? -l set locale from the ones given in
#? <https://github.com/citation-style-language/locales>, e.g. "pt-BR"
Expand All @@ -55,8 +55,9 @@
#? doi2text and doi2bib <https://github.com/schneiderfelipe/doi2bib>
#? are licensed under the MIT License.

style="american-chemical-society"

locale=$(locale | grep LANGUAGE | cut -d= -f2 | cut -d: -f1 | tr '_' '-')
style="chicago-author-date"
if [ ! $locale ]; then
locale="en-US"
fi
Expand All @@ -75,7 +76,7 @@ while getopts ":hvs:Sl:L" opt "$@"; do
style="${OPTARG}"
;;
S) # list all styles
curl -s -X GET \
curl -X GET \
https://api.github.com/repos/citation-style-language/styles/contents/\?ref\=master | \
sed -e '/"name":.*\.csl"/{s/\s*"name": "//;s/\.csl",\s*//;p};d'
exit 0
Expand All @@ -84,7 +85,7 @@ while getopts ":hvs:Sl:L" opt "$@"; do
locale="${OPTARG}"
;;
L) # list all styles
curl -s -X GET \
curl -X GET \
https://api.github.com/repos/citation-style-language/locales/contents/\?ref\=master | \
sed -e '/"name":.*\.xml"/{s/\s*"name": "//;s/\.xml",\s*//;s/locales-//;p};d'
exit 0
Expand All @@ -108,7 +109,10 @@ for doi in "$@"; do
# we do some encoding as needed.
doi=${doi//+/%2B}
http_headers="Accept: text/x-bibliography; style=${style}; locale=${locale}"

echo "$http_headers"
echo

# we retrieve the data from https://doi.org/
curl -s -LH "$http_headers" "https://doi.org/${doi}"
curl -LH "$http_headers" "https://doi.org/${doi}"
done