summaryrefslogtreecommitdiff
path: root/getarxiv
blob: f1c78082483f4f417b65e8a3e10830c7dd55581e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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