#!/bin/sh -
PATH=$PATH:/l/palm/bin

urls='http://www.x-rates.com/d/USD/table.html'
#urls='http://www.radiks.net/~rhuebner/PPCurrency.prc'	# Parens plugin

title='Currency Exchange Rates'
destdir="${PALMINST-$HOME/l/palm/install}"
dest="$destdir/currency.pdb"

# clipcurrency - personalized Palm web clipper for currency exchange rates
# Steve Kinzler, steve@kinzler.com, Apr 99/Nov 01
# https://kinzler.com/me/home.html#palm

case "$#" in
0)	;;
*)	echo "usage: $0" 1>&2; exit 1;;
esac

tmpA=/tmp/ccA$$
tmpB=/tmp/ccB$$
trap "rm -f $tmpA $tmpB; exit" 0 1 2 13 15

for url in $urls
do
	case "$url" in
	*.prc)	file=`echo "$url" | sed 's/.*\///'`
		lynx -source "$url" > "$destdir/$file"
		case `file "$destdir/$file"` in
		*data*|*[Pp]alm*)	;;
		*)			echo "$0: cannot get $url" 1>&2
					rm -f "$destdir/$file";;
		esac;;

	*)	lynx -dump -nolist "$url";;
	esac
done > $tmpA
grep '^lynx: ' $tmpA && exit $?

sed -n 's/  */ /g; s/^ //; s/ $//
	/^American Dollar/,/^using values from /p' < $tmpA |
sed '/^American Dollar/s/$/ 1_US$ in_US$/; /^click on /d' > $tmpB

test -s $tmpB || exit 0

txt2pdbdoc "$title" $tmpB "$dest"
