From 1770f5db7d9a9256262fc8ef902daad499513fa2 Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Thu, 14 Jan 2016 13:18:16 +0500 Subject: Add ledger price-db update script. --- ledger-price-db-update.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 ledger-price-db-update.sh (limited to 'ledger-price-db-update.sh') diff --git a/ledger-price-db-update.sh b/ledger-price-db-update.sh new file mode 100755 index 0000000..ff10504 --- /dev/null +++ b/ledger-price-db-update.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Get currency exchanges rate and update a ledger price file. +# + +set -e + +LEDGER="$HOME/.ledgerrc" +if [[ ! -f "$LEDGER" ]] ; then + echo "No ledger configuration file: $LEDGER" >&2 + exit 13 +fi +PRICE_DB_FILE=$(sed -nE "s/^--price-db (.*)/\1/p" "$LEDGER") +PRICE_DB_FILE="${PRICE_DB_FILE/#\~/$HOME}" + +xe() { + curl -s "http://download.finance.yahoo.com/d/quotes.csv?s=$1&f=p" +} + +echo P $(date +"%Y/%m/%d %H:%M:%S") \$ $(xe "USDRUB=X") R >> "$PRICE_DB_FILE" +echo P $(date +"%Y/%m/%d %H:%M:%S") € $(xe "EURRUB=X") R >> "$PRICE_DB_FILE" -- cgit v1.2.3