diff options
-rwxr-xr-x | getarxiv | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/getarxiv b/getarxiv new file mode 100755 index 0000000..f1c7808 --- /dev/null +++ b/getarxiv @@ -0,0 +1,48 @@ +#!/bin/sh +# +# (c) 2020 Vincenzo "KatolaZ" Nicosia <katolaz@freaknet.org> +# +# Get a bibtex reference from an arxiv id given as argument +# +# deps: xml2tsv (https://git.katolaz.net/xml2tsv/) +# +# Use, modify, and redistribute under the terms of the MIT/X11 License: +# +# https://directory.fsf.org/wiki/License:X11 +# + +url="http://export.arxiv.org/api/query?id_list=" + +if [ $# -lt 1 ]; then + read -r doi +else + doi=$1 +fi + +doi=${doi#ar[xX]iv:} + +res=$(curl -s "${url}${doi}" | xml2tsv) + + +title=$(echo "$res" | grep -E "^/feed/entry/title" | cut -d " " -f 2 | tr '\n' ' ' | sed -r 's/[ \t]*([ \t])/\1/g;s/[ \t]$//g') +authors=$(echo "$res" | grep -E "^/feed/entry/author/name" | cut -d " " -f 2 | tr '\n' '|' | sed -r 's/\|$//;s:\|: and :g' ) +year=$(echo "$res" | grep -E "^/feed/entry/published" | cut -d " " -f 2 | cut -d "-" -f 1 ) +primary=$(echo "$res" | grep -E "^/feed/entry/arxiv:primary_category" | tr "\t" "\n" | grep "^term=" | cut -d "=" -f 2) +categories=$(echo "$res" | grep -E "^/feed/entry/category" | tr '\t' '\n' | grep "^term=" | cut -d "=" -f 2 | tr '\n' ',' | sed -r 's/,$//g') +first_auth=$(echo "$authors" | sed -r 's/ and /@/' | cut -d "@" -f 1 | awk '{print $NF; }' ) + +## if title is empty, the id was most probably wrong, so bail out +[ -z "$title" ] && exit 1 + +cat <<EOF +@misc{${first_auth}$year, + title={$title}, + author={$authors}, + year={$year}, + eprint={$doi}, + primaryClass={$primary}, + additionalClass={$categories}, +} +EOF + +exit 0 |