diff options
| author | Anton Bobov <abobov@gmail.com> | 2017-11-06 12:39:55 +0500 |
|---|---|---|
| committer | Anton Bobov <abobov@gmail.com> | 2017-11-15 16:32:12 +0500 |
| commit | 3381572cd3f1c6f628e17de824267505135a3401 (patch) | |
| tree | c3c15461ed5c4620812cc05aeadefcbc6e377db9 /ledger-price-db-update.sh | |
| parent | 1f44d74c080c168ccdb315f18a99f270f09c548d (diff) | |
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.
Diffstat (limited to 'ledger-price-db-update.sh')
| -rwxr-xr-x | ledger-price-db-update.sh | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/ledger-price-db-update.sh b/ledger-price-db-update.sh index 478efb9..46d7bb5 100755 --- a/ledger-price-db-update.sh +++ b/ledger-price-db-update.sh @@ -2,9 +2,15 @@ # # Get currency exchanges rate and update a ledger price file. # +# Read commodities from file in format: COMMODITY SYMBOL (ex.: EURUSD $) set -e +LEDGER_COMMODITIES="$HOME/.ledger-commodities" +if [ ! -f "$LEDGER_COMMODITIES" ] ; then + echo "No ledger commodities files: $LEDGER_COMMODITIES" + exit 1 +fi LEDGER="$HOME/.ledgerrc" if [[ ! -f "$LEDGER" ]] ; then echo "No ledger configuration file: $LEDGER" >&2 @@ -13,22 +19,18 @@ 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" -} - print_rate() { currency="$1" symbol="$2" val=$(xe "$currency=X") - test -n "$val" && echo P $(date +"%Y/%m/%d %H:%M:%S") $symbol $val R + [[ $val =~ ^[0-9]+\.[0-9]+$ ]] && echo P $(date +"%Y/%m/%d %H:%M:%S") $symbol $val R } { - print_rate "USDRUB" "\$" - print_rate "EURRUB" "€" - print_rate "PLNRUB" "P" + cat "$LEDGER_COMMODITIES" | while read commodity symbol ; do + print_rate "$commodity" "$symbol" + done } >> "$PRICE_DB_FILE" |
