summaryrefslogtreecommitdiffstats
path: root/util/bin/google.currency
blob: 8a3f708f95357ce5c47fa467e070f4bcf040bc2e (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
#! /bin/sh
set -euf

tc=${TC:="usd"}
sc=${SC:="eur"}

usage(){
  echo 'TC= targetcurrency, valid strings are in the style of "usd", "eur" or "sgd". default "usd"'
  echo 'SC= sourcecurrency, same as TC, default is eur'
  echo 'Example: TC="sgd" ./currency.google 11'

  exit 0
}

currency_convert(){
  text=$*
  url="http://www.google.com/finance/converter?a=$1&from=$sc&to=$tc"
  curl -A "Mozilla/5.0" -Ss "$url" |
    sed '/res/!d;s/<[^>]*>//g' |
    #sed 's/\[\[\[\"//' |
    awk '{print $4}'
}

if [ $# -eq 0 ]; then
  usage
fi

currency_convert $*