: ########################################################################## # Title : currencycvt - convert currencies # Author : Heiner Steven # Date : 2002-08-06 # Requires : wget, urlencode # Category : WWW, Desktop # SCCS-Id. : @(#) currencycvt 1.6 07/04/18 ########################################################################## # Description # ########################################################################## PN=`basename "$0"` # Program name VER='1.6' : ${GETURL:=wget} : ${GETURLFLAGS="-q -O-"} : ${AWK:=awk} CurrencyListURL=http://www.oanda.com/convert/classic CurrencyListCache=/tmp/$PN.cache # The following URL may contain the variables $incode, $outcode, $value, and # $date which will be replaced with the values the user specified CurrencyConvertURL='http://www.oanda.com/convert/classic?value=$value&exch=$incode&expr=$outcode&date=$date' FROMCODE=USD # Defaults TOCODE=EUR today=`date +%m/%d/%y` Usage () { echo >&2 "$PN - convert currencies, $VER usage: $PN [-i fromcode] [-o tocode] [-d date] [amount ...] or $PN searchpattern options: -i: input currency code (default $FROMCODE) -o: output currency code (default $TOCODE) -d: date in the format YYYY-MM-DD (default: today) The first usage converts the given amount (default: 1) from the input currency into the output currency. The second form is used to look up currency codes: the searchpattern is assumed to be the name of a country or a currency. This script uses the excellent service of OANDA.com: $CurrencyListURL" exit 1 } Msg () { for MsgLine do echo "$PN: $MsgLine" >&2 done } Fatal () { Msg "$@"; exit 1; } # canonws - "canonical" white space # replace sequences of tab and blank characters with one blank canonws () { sed 's/ / /g; s/ */ /g; s/^ *//; s/ $//' "$@" } GetCurrencyList () { if [ -s "$CurrencyListCache" ] then # Use cached version cat "$CurrencyListCache" else Msg "retrieving currency list (will be saved in $CurrencyListCache)" # The complicated looking "sed" expressions search for HTML code # of the form