blob: 7612164ff86f4d1505cad8a5c441c246359c0428 (
plain) (
blame)
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
|
#!/bin/bash
set -e
if [ $# = 0 ] ; then
exit 0
fi
from=${1:0:3}
to=${1:3:3}
get_value() {
curl -s "http://www.xe.com/currencyconverter/convert/?Amount=1&From=$from&To=$to" | \
grep -o "<span class='uccResultAmount'>[^<]\+" | \
grep -o '[0-9\.]\+'
}
get_value_at_date() {
date=$(date -d "$1" +%F)
curl -s "http://www.xe.com/currencytables/?from=$from&date=$date" | \
xmllint --nonet --html --xpath "//table[@id='historicalRateTbl']/tbody/tr[td/a/text() = '${to^^}']/td[3]/text()" - 2>/dev/null
}
if [ -z "$2" ] ; then
val=$(get_value)
else
val=$(get_value_at_date "$2")
fi
printf '%.4f\n' $val
|