Curcy version 0.1
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 10 Mar 2008 13:32:58 +0000 (13:32 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 10 Mar 2008 13:32:58 +0000 (13:32 +0000)
Makefile [new file with mode: 0644]
README [new file with mode: 0644]
curcy-update [new file with mode: 0755]
currencies [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/cron.weekly [new file with mode: 0644]
debian/rules [new file with mode: 0755]
license [new file with mode: 0644]

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..8c01f4b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+all:
+
+clean:
+
+install: all
+       mkdir -p $(DESTDIR)/usr/sbin
+       mkdir -p $(DESTDIR)/usr/share
+       cp curcy-update $(DESTDIR)/usr/sbin
+       cp -p currencies $(DESTDIR)/usr/share
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..0b0e125
--- /dev/null
+++ b/README
@@ -0,0 +1,19 @@
+== Why a currency rate database on the system?
+
+Whenever you work at a multi locale project, currencies become a topic of
+concern sooner or later. Sometimes you can have a some rates for a few
+currencies, that you lazilly updates. What you need is a simple way to get
+curency rate.
+
+== Why that format?
+
+The encoding is compataible with most charsets, including ascii7. It does not contain any locale specific data.
+
+It's really basic. Each line has the syntax:
+<3 letter international currency code>=<decimal value>
+
+All the lines do have the same value
+Exemple:
+GBP=1.4758
+USD=0.7469
+means than $ 0.7469 = £ 1.4758
diff --git a/curcy-update b/curcy-update
new file mode 100755 (executable)
index 0000000..573d838
--- /dev/null
@@ -0,0 +1,113 @@
+#!/usr/bin/env bash
+#
+# This script builds a file, usually /var/share/currencies where each line as the syntax
+# <3 letter international currency code>=<decimal value>
+# All the lines do have the same value
+# Exemple:
+# GBP=1.4758
+# USD=
+# means than $ = £ 1.4758
+#
+# You are free to copy / modify / redistribute / resell that file, just keep the author name.
+# Author: Jean-Michel Vourgère <jmv_deb@nirgal.com>
+
+set -e
+
+target_file=/var/share/currencies
+REFERENCE="EUR"
+unset verbose
+unset aggressive
+
+curlcmd="curl --user-agent curcy -s -S"
+
+function usage() {
+    #echo $'\n' $@ $'\n'
+    echo "Usage: curcy-update [options]"
+    echo "  -v|--verbose        Display informational messages"
+    echo "  -l|--listonly       Just list the supported currencies"
+    echo "  --aggressive        Don't sleep between server requests"
+    echo "  --target=<filename>  Set target filename. Defaults to /var/share/currencies"
+}
+
+function parsearg() {
+    _OPT="${1%=?*}"
+    _VAL="${1#?*=}"
+}
+
+for arg in "$@"; do
+    parsearg $arg
+
+    case $_OPT in
+    -v|--verbose)
+        verbose=1
+        continue
+    ;;
+    -l|--listonly)
+        listonly=1
+        continue
+    ;;
+    --aggressive)
+        echo "Setting aggressive"
+        aggressive=1
+        continue
+    ;;
+    -h|--help)
+        usage 
+        exit 0
+    ;;
+    --target)
+        target_file=$_VAL
+        continue
+    ;;
+    *)
+        echo "Unknown option $_OPT"
+        exit 22
+    ;;
+    esac
+done
+
+# get list of curencies
+currencies=`$curlcmd "http://finance.yahoo.com/currency/convert?amt=1&from=${REFERENCE}&to=${REFERENCE}" \
+    | grep yfnc_tabledata1 \
+    | sed -e "s/<select name=\"from\">\(.*\)<\/select>.*<select.*/\1/g" \
+    | sed -e "s/selected //g" \
+    | sed -e "s/<option value=\"/\n/g" \
+    | grep -v script \
+    | cut -d \" -f 1`
+
+if [ -n "$listonly" -o "$verbose" ]; then
+    echo "Supported currencies:"
+    for c in $currencies; do
+        echo -n $c$' '
+    done
+    echo
+    if [ -n "$listonly" ]; then
+        exit 0
+    fi
+fi
+
+[ -f $target_file.new ] && rm -r $target_file.new
+for c in $currencies; do
+    # google doesn't do many currencies; yahoo is better in that regard
+    #equiv=`curl -s -S "http://finance.google.com/finance?q=${c}${REFERENCE}&hl=en" \
+    #    | grep -E "&nbsp;1&nbsp;${c}&nbsp;=<b>&nbsp;[0-9]+\.[0-9]+&nbsp;${REFERENCE}&nbsp;</b>" \
+    #    | sed -e "s/^&nbsp;1&nbsp;${c}&nbsp;=<b>&nbsp;\(.*\)&nbsp;${REFERENCE}&nbsp;<\/b>/\1/g"`
+
+    # http://finance.google.com/robots.txt allows /currency
+
+    equiv=`$curlcmd "http://finance.yahoo.com/currency/convert?amt=1&from=${c}&to=${REFERENCE}" \
+        | grep yfnc_tabledata1 \
+        | sed -e "s/.*<\/b>.*<b>\(.*\)<\/b>.*/\1/g"`
+    
+    if [ -n "$verbose" ]; then
+        echo 1 $c = $equiv $REFERENCE
+    fi
+    echo $c=$equiv>> $target_file.new
+
+    if [ -z "$aggressive" ]; then
+        # be nice with server: wait 1 to 2 minutes
+        sleep $(( 60 + $RANDOM % 60 ))
+    fi
+done
+
+mv $target_file.new $target_file
diff --git a/currencies b/currencies
new file mode 100644 (file)
index 0000000..052ba8a
--- /dev/null
@@ -0,0 +1,155 @@
+ALL=0.008127
+DZD=0.01100
+XAL=0.9560
+ARS=0.2428
+AWG=0.4171
+AUD=0.6290
+BSD=0.7469
+BHD=1.9808
+BDT=0.01086
+BBD=0.3734
+BYR=0.0003483
+BZD=0.3791
+BMD=0.7461
+BTN=0.01632
+BOB=0.09424
+BWP=0
+BRL=0.3905
+GBP=1.4758
+BND=0.4845
+BGN=0.5103
+BIF=0.0006934
+KHR=0
+CAD=0.6993
+CVE=0
+KYD=0.9108
+XOF=0.001522
+XAF=0.001523
+CLP=0.001422
+CNY=0.09794
+COP=0.0003904
+KMF=0.002023
+XCP=2.5542
+CRC=0.001442
+HRK=0.1360
+CUP=0.7469
+CYP=1.7071
+CZK=0.03502
+DKK=0.1342
+DJF=0
+DOP=0.02310
+XCD=0.2766
+ECS=0.00002987
+EGP=0.1310
+SVC=0.08535
+ERN=0
+EEK=0.06379
+ETB=0.08274
+EUR=1.0000
+FKP=0
+FJD=0.4642
+GMD=0.02771
+GHC=0.00008058
+GIP=0
+XAU=489.75
+GTQ=0.09737
+GNF=0.0002165
+GYD=0
+HTG=0.02110
+HNL=0.03954
+HKD=0.09553
+HUF=0.003993
+ISK=0.01198
+INR=0.01839
+IDR=0.00008259
+IRR=0.00008051
+IQD=0.0005931
+ILS=0.1807
+JMD=0.01094
+JPY=0.006050
+JOD=1.0541
+KZT=0.005819
+KES=0.01125
+KRW=0.0008037
+KWD=2.5923
+LAK=0
+LVL=1.4341
+LBP=0.0004938
+LSL=0.1029
+LRD=0
+LYD=0
+LTL=0.2891
+MOP=0.09328
+MKD=0.01620
+MWK=0.005316
+MYR=0.2163
+MVR=0.05835
+MTL=2.3266
+MRO=0.002917
+MUR=0.02367
+MXN=0.06930
+MDL=0.06070
+MNT=0.0006425
+MAD=0.08945
+MMK=0
+NAD=0.1041
+NPR=0.01051
+ANG=0.4172
+TRY=0.5712
+NZD=0.5639
+ZWN=0.002987
+NIO=0.04142
+NGN=0.005860
+KPW=0
+NOK=0.1238
+OMR=1.9399
+XPF=0.008180
+PKR=0.01232
+XPD=275.78
+PAB=0.7469
+PGK=0.2474
+PYG=0.0001464
+PEN=0.2357
+PHP=0.01611
+XPT=973.64
+PLN=0.2634
+QAR=0.2052
+RON=0.3071
+RUB=0.02874
+RWF=0.001369
+WST=0.2897
+STD=0.00005529
+SAR=0.1991
+SCR=0.1187
+SLL=0.0002502
+XAG=9.8839
+SGD=0.4856
+SKK=0.02948
+SIT=0.004165
+SBD=0.1087
+SOS=0
+ZAR=0.1047
+LKR=0.006736
+SHP=0
+SDD=0.003186
+SZL=0.1041
+SEK=0.1060
+CHF=0.6015
+SYP=0
+TWD=0.02251
+TZS=0.0005951
+THB=0.02302
+TOP=0.3764
+TTD=0.1195
+TND=0.5730
+USD=0.7469
+AED=0.2033
+UGX=0.0004526
+UAH=0.1485
+UYU=0.03067
+VUV=0.007578
+VEB=0.0003478
+VND=0.00004632
+YER=0.003771
+ZMK=0.0001905
+ZWD=0.002987
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..fb95cfe
--- /dev/null
@@ -0,0 +1,5 @@
+curcy (0.1) UNRELEASED; urgency=low
+
+  * Initial release.
+
+ --  Jean-Michel Vourgère <jmv_deb@nirgal.com>  Sat, 16 Jun 2007 22:31:13 +0200
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..b4bba2b
--- /dev/null
@@ -0,0 +1,13 @@
+Source: curcy
+Section: contrib/misc
+Priority: optional
+Maintainer: Jean-Michel Vourgère  <debspam@nirgal.com>
+Build-Depends: debhelper (>> 3.0.0)
+Standards-Version: 3.7.2.2
+
+Package: curcy
+Section: contrib/misc
+Architecture: any
+Depends: curl
+Description: Currency rates database builder
+ Weekly builds a database in /usr/share/currencies.
diff --git a/debian/cron.weekly b/debian/cron.weekly
new file mode 100644 (file)
index 0000000..2fbe83a
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/sh
+/usr/sbin/update-curcy
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..3f5646d
--- /dev/null
@@ -0,0 +1,82 @@
+#!/usr/bin/make -f
+# Sample debian/rules that uses debhelper.
+# GNU copyright 1997 to 1999 by Joey Hess.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+# This is the debhelper compatibility version to use.
+export DH_COMPAT=4
+
+CFLAGS = -g
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+
+build: build-stamp
+build-stamp:
+       dh_testdir
+
+       # Add here commands to compile the package.
+       -$(MAKE)
+       #docbook-to-man debian/gentoo.sgml > gentoo.1
+
+       touch build-stamp
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp
+
+       # Add here commands to clean up after the build process.
+       -$(MAKE) clean
+
+       dh_clean
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k
+       dh_installdirs
+       
+       # Add here commands to install the package into debian/curcy.
+       $(MAKE) install DESTDIR=$(CURDIR)/debian/curcy
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+#      dh_installdebconf
+       dh_installdocs
+       dh_installexamples
+       dh_installmenu
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_installinit
+       dh_installcron
+       dh_installman
+       dh_installinfo
+#      dh_undocumented
+       dh_installchangelogs
+       dh_link
+       dh_strip
+       dh_compress
+       dh_fixperms
+#      dh_makeshlibs
+       dh_installdeb
+#      dh_perl
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install
diff --git a/license b/license
new file mode 100644 (file)
index 0000000..6466c69
--- /dev/null
+++ b/license
@@ -0,0 +1,16 @@
+Intellectual property is a human pleague causing much misery throughout the world.
+You are free to copy / modify / redistribute / resell theses files.
+
+© 2007 Jean-Michel Vourgère <jmv_deb@nirgal.com>
+
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGE.