From 3381572cd3f1c6f628e17de824267505135a3401 Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Mon, 6 Nov 2017 12:39:55 +0500 Subject: Exchange rate query script, ledger price db update config. Move XE function out from the ledger-price-db-update and introduce ledger-commodities configuration file. --- xe | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 xe (limited to 'xe') diff --git a/xe b/xe new file mode 100755 index 0000000..7612164 --- /dev/null +++ b/xe @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +if [ $# = 0 ] ; then + exit 0 +fi + +from=${1:0:3} +to=${1:3:3} + +get_value() { + curl -s "http://www.xe.com/currencyconverter/convert/?Amount=1&From=$from&To=$to" | \ + grep -o "[^<]\+" | \ + grep -o '[0-9\.]\+' +} + +get_value_at_date() { + date=$(date -d "$1" +%F) + curl -s "http://www.xe.com/currencytables/?from=$from&date=$date" | \ + xmllint --nonet --html --xpath "//table[@id='historicalRateTbl']/tbody/tr[td/a/text() = '${to^^}']/td[3]/text()" - 2>/dev/null +} + +if [ -z "$2" ] ; then + val=$(get_value) +else + val=$(get_value_at_date "$2") +fi + +printf '%.4f\n' $val -- cgit v1.2.3