Figure out a bibtex entry from a arxiv url or number.
authorFrancois Fleuret <francois@fleuret.org>
Sat, 17 Jun 2017 10:48:07 +0000 (12:48 +0200)
committerFrancois Fleuret <francois@fleuret.org>
Sat, 17 Jun 2017 10:48:07 +0000 (12:48 +0200)
arxiv-bib.sh

index 3654b3b..3097a79 100755 (executable)
@@ -23,28 +23,44 @@ set -o pipefail
 
 tmp=$(mktemp /tmp/arxiv-bib.sh.XXXXXX)
 
-curl > "${tmp}" "https://arxiv.org/abs/$1"
+while [[ "$1" ]]
+do
 
-AUTHORS=""
+    id="$1"
 
-while read line
-do
-    [[ "${AUTHORS}" ]] && AUTHORS="${AUTHORS} and "
-    AUTHORS="${AUTHORS}${line}"
-done < <(grep '<meta name="citation_author"' "${tmp}" | sed -e 's/^.*content="\([^,]*, .\).*$/\1./')
+    if [[ ${id} =~ ^http ]]
+    then
+        id="$(echo "${id}" | sed -e 's|^.*/\([^\]*\)$|\1|')"
+    fi
+
+    curl -s > "${tmp}" "https://arxiv.org/abs/${id}"
+
+    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/')
+    TITLE=$(grep '<meta name="citation_title"' ${tmp} | sed -e 's/^.*content="\([^"]*\)".*$/\1/')
+    YEAR=$(echo ${id} | sed -e 's/^\(..\).*$/20\1/')
 
-cat <<EOF
-@article{arxiv-$1,
+    cat <<EOF
+@article{arxiv-${id},
   author={${AUTHORS}},
   title={${TITLE}},
   journal={CoRR},
-  volume={abs/$1},
+  volume={abs/${id}},
   year={${YEAR}},
-  url={https://arxiv.org/pdf/$1}
+  url={https://arxiv.org/pdf/${id}}
 }
 EOF
 
-rm -rf ${tmp}
+    shift
+
+done
+
+
+
+      rm -rf ${tmp}