diff options
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" |
