From 24d87e79b305944fe34d52d742853bd017bf5f77 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Michel=20Nirgal=20Vourg=C3=A8re?= Date: Mon, 10 Mar 2008 13:32:58 +0000 Subject: [PATCH] Curcy version 0.1 --- Makefile | 9 +++ README | 19 ++++++ curcy-update | 113 +++++++++++++++++++++++++++++++++ currencies | 155 +++++++++++++++++++++++++++++++++++++++++++++ debian/changelog | 5 ++ debian/control | 13 ++++ debian/cron.weekly | 2 + debian/rules | 82 ++++++++++++++++++++++++ license | 16 +++++ 9 files changed, 414 insertions(+) create mode 100644 Makefile create mode 100644 README create mode 100755 curcy-update create mode 100644 currencies create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/cron.weekly create mode 100755 debian/rules create mode 100644 license diff --git a/Makefile b/Makefile new file mode 100644 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 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>= + +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 index 0000000..573d838 --- /dev/null +++ b/curcy-update @@ -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>= +# 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 + +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= 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/