helpFound

This commit is contained in:
ackman678
2020-02-13 12:11:29 -08:00
parent cf734dc8aa
commit 74b88b38eb
9 changed files with 130 additions and 35 deletions

View File

@@ -1,31 +1,49 @@
#!/bin/bash
#pdf2bib
# usage:
# pdf2bib.sh file.pdf
# depends:
# xsltproc - xml processor, from GNOME project
# pubmed2bibtex.xsl - xml processor stylesheet
#James Ackman 2018-11-07T14:41:53-08:00
if [ "$1" == "-h" ] ; then
echo "
pdf2bib - search for a doi within a pdf, query pubmed, and append bibtex entry with pdf to your local bib database file. Last two steps are identical to sdoi.sh
usage:
pdf2bib.sh file.pdf
depends:
pdftotext - from ghostscript or poppler or texlive ?
xsltproc - xml processor, from GNOME project
pubmed2bibtex.xsl - xml processor stylesheet
defaults:
Set the three required default file locations (xsl file, bib file, pdf directory)
"
exit 0
fi
#Setup defaults
styleSheet="$HOME/bin/pubmed2bibtex.xsl"
bibdFileOut="$HOME/projects/bibd/OMEGA.bib"
pdfPathOut="$HOME/projects/bibd/papers"
styleSheet=${pubmedStyleSheet:-$HOME/bin/pubmed2bibtex.xsl}
bibdFileOut=${bibdFileOut:-$HOME/projects/bibd/OMEGA.bib}
pdfPathOut=${pdfPathOut:-$HOME/projects/bibd/papers}
relPath=$(basename $pdfPathOut)
fn=$1
set -e #exit if an error
echo "using $pdfPathOut"
echo "using $bibdFileOut"
#try to extract doi from pdf and retrieve a pubmed id
#for 'DOI:' syntax
doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -i doi: --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#doi:(.+)#\1#")
#for 'https://doi.org' syntax
if [ -z "$doi" ]; then
doi=$(pdftotext -q -f 1 -l 1 $fn - | grep -i "doi.org/" --max-count=1 | tr [:upper:] [:lower:] | sed -E "s#.+doi\.org\/(.+)#\1#")
fi
if [ -z "$doi" ]; then
echo "doi not found"
exit 1
fi
## TODO: dedupe this with sdoi.sh
uid=$(curl -s "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=$doi&field=doi&retmode=xml" | grep -E "<Id>[0-9]+</Id>" | sed -E "s#<Id>([0-9]+)</Id>#\1#")