3 # This script builds a file, usually /var/share/currencies where each line as the syntax
4 # <3 letter international currency code>=<decimal value>
5 # All the lines do have the same value
9 # means than $ = £ 1.4758
11 # You are free to copy / modify / redistribute / resell that file, just keep the author name.
12 # Author: Jean-Michel Vourgère <jmv_deb@nirgal.com>
16 target_file=/var/share/currencies
21 curlcmd="curl --user-agent curcy -s -S"
25 echo "Usage: curcy-update [options]"
26 echo " -v|--verbose Display informational messages"
27 echo " -l|--listonly Just list the supported currencies"
28 echo " --aggressive Don't sleep between server requests"
29 echo " --target=<filename> Set target filename. Defaults to /var/share/currencies"
50 echo "Setting aggressive"
63 echo "Unknown option $_OPT"
69 # get list of curencies
70 currencies=`$curlcmd "http://finance.yahoo.com/currency/convert?amt=1&from=${REFERENCE}&to=${REFERENCE}" \
71 | grep yfnc_tabledata1 \
72 | sed -e "s/<select name=\"from\">\(.*\)<\/select>.*<select.*/\1/g" \
73 | sed -e "s/selected //g" \
74 | sed -e "s/<option value=\"/\n/g" \
78 if [ -n "$listonly" -o "$verbose" ]; then
79 echo "Supported currencies:"
80 for c in $currencies; do
84 if [ -n "$listonly" ]; then
89 [ -f $target_file.new ] && rm -r $target_file.new
90 for c in $currencies; do
91 # google doesn't do many currencies; yahoo is better in that regard
92 #equiv=`curl -s -S "http://finance.google.com/finance?q=${c}${REFERENCE}&hl=en" \
93 # | grep -E " 1 ${c} =<b> [0-9]+\.[0-9]+ ${REFERENCE} </b>" \
94 # | sed -e "s/^ 1 ${c} =<b> \(.*\) ${REFERENCE} <\/b>/\1/g"`
96 # http://finance.google.com/robots.txt allows /currency
98 equiv=`$curlcmd "http://finance.yahoo.com/currency/convert?amt=1&from=${c}&to=${REFERENCE}" \
99 | grep yfnc_tabledata1 \
100 | sed -e "s/.*<\/b>.*<b>\(.*\)<\/b>.*/\1/g"`
102 if [ -n "$verbose" ]; then
103 echo 1 $c = $equiv $REFERENCE
105 echo $c=$equiv>> $target_file.new
107 if [ -z "$aggressive" ]; then
108 # be nice with server: wait 1 to 2 minutes
109 sleep $(( 60 + $RANDOM % 60 ))
113 mv $target_file.new $target_file