Initial commit.
authorFrancois Fleuret <francois@fleuret.org>
Mon, 12 Jun 2017 07:55:25 +0000 (09:55 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Mon, 12 Jun 2017 07:55:25 +0000 (09:55 +0200)
arxiv-bib.sh [new file with mode: 0755]

diff --git a/arxiv-bib.sh b/arxiv-bib.sh
new file mode 100755 (executable)
index 0000000..3654b3b
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+#########################################################################
+# This program is free software: you can redistribute it and/or modify  #
+# it under the terms of the version 3 of the GNU General Public License #
+# as published by the Free Software Foundation.                         #
+#                                                                       #
+# This program is distributed in the hope that it will be useful, but   #
+# WITHOUT ANY WARRANTY; without even the implied warranty of            #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      #
+# General Public License for more details.                              #
+#                                                                       #
+# You should have received a copy of the GNU General Public License     #
+# along with this program. If not, see <http://www.gnu.org/licenses/>.  #
+#                                                                       #
+# Written by and Copyright (C) Francois Fleuret                         #
+# Contact <francois.fleuret@idiap.ch> for comments & bug reports        #
+#########################################################################
+
+
+set -e
+set -o pipefail
+
+tmp=$(mktemp /tmp/arxiv-bib.sh.XXXXXX)
+
+curl > "${tmp}" "https://arxiv.org/abs/$1"
+
+AUTHORS=""
+
+while read line
+do
+    [[ "${AUTHORS}" ]] && AUTHORS="${AUTHORS} and "
+    AUTHORS="${AUTHORS}${line}"
+done < <(grep '<meta name="citation_author"' "${tmp}" | sed -e 's/^.*content="\([^,]*, .\).*$/\1./')
+
+TITLE=$(grep '<meta name="citation_title"' x | sed -e 's/^.*content="\([^"]*\)".*$/\1/')
+YEAR=$(echo $1 | sed -e 's/^\(..\).*$/20\1/')
+
+cat <<EOF
+@article{arxiv-$1,
+  author={${AUTHORS}},
+  title={${TITLE}},
+  journal={CoRR},
+  volume={abs/$1},
+  year={${YEAR}},
+  url={https://arxiv.org/pdf/$1}
+}
+EOF
+
+rm -rf ${tmp}