Initial commit.
[scripts.git] / arxiv-bib.sh
1 #!/bin/bash
2
3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify  #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation.                         #
7 #                                                                       #
8 # This program is distributed in the hope that it will be useful, but   #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of            #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
11 # General Public License for more details.                              #
12 #                                                                       #
13 # You should have received a copy of the GNU General Public License     #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.  #
15 #                                                                       #
16 # Written by and Copyright (C) Francois Fleuret                         #
17 # Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
18 #########################################################################
19
20
21 set -e
22 set -o pipefail
23
24 tmp=$(mktemp /tmp/arxiv-bib.sh.XXXXXX)
25
26 curl > "${tmp}" "https://arxiv.org/abs/$1"
27
28 AUTHORS=""
29
30 while read line
31 do
32     [[ "${AUTHORS}" ]] && AUTHORS="${AUTHORS} and "
33     AUTHORS="${AUTHORS}${line}"
34 done < <(grep '<meta name="citation_author"' "${tmp}" | sed -e 's/^.*content="\([^,]*, .\).*$/\1./')
35
36 TITLE=$(grep '<meta name="citation_title"' x | sed -e 's/^.*content="\([^"]*\)".*$/\1/')
37 YEAR=$(echo $1 | sed -e 's/^\(..\).*$/20\1/')
38
39 cat <<EOF
40 @article{arxiv-$1,
41   author={${AUTHORS}},
42   title={${TITLE}},
43   journal={CoRR},
44   volume={abs/$1},
45   year={${YEAR}},
46   url={https://arxiv.org/pdf/$1}
47 }
48 EOF
49
50 rm -rf ${tmp}