diff options
| author | Anton Bobov <abobov@gmail.com> | 2016-01-14 13:18:16 +0500 |
|---|---|---|
| committer | Anton Bobov <abobov@gmail.com> | 2016-01-20 15:33:32 +0500 |
| commit | 1770f5db7d9a9256262fc8ef902daad499513fa2 (patch) | |
| tree | 50f2c92cceb26273c7d611768dd55fb0acd6c968 | |
| parent | bc9599bb7dbb900ba8636baba8f27f349d3dff0e (diff) | |
Add ledger price-db update script.
| -rwxr-xr-x | ledger-price-db-update.sh | 21 |
1 files changed, 21 insertions, 0 deletions
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" |
