From 818d316adec9390a35231b44c827a493352a2cdc Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sun, 5 Jan 2020 08:06:00 +0000 Subject: add getarxiv to create bibtex entries from arxiv IDs --- getarxiv | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 getarxiv 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 +# +# 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 <