Skip to content

Instantly share code, notes, and snippets.

@vkurup
Created November 23, 2011 20:43
Show Gist options
  • Save vkurup/1389840 to your computer and use it in GitHub Desktop.
Save vkurup/1389840 to your computer and use it in GitHub Desktop.
Take formatted commodity output from ledger and feed it to getquote
#!/bin/bash
# Reads from STDIN looking for ledger-formatted commodity symbols. Uses
# getquote (Perl script) to lookup the lastest price for commodity, then
# appends to PRICEDB file.
#
# Usage:
# ledger -n bal ^Assets:Investments | glue-quote.sh
#
# Assumes that you have 'getquote' on your path
LEDGER_PRICEDB=$HOME/.pricedb
TOUCHED=
while read data; do
SYMBOL=`echo $data | awk '{ print $2 }'`
if [ $SYMBOL ]
then
PRICE=`getquote $SYMBOL`
DATE=$(date '+%Y/%m/%d %T')
echo "P $DATE $SYMBOL $PRICE" >> $LEDGER_PRICEDB
TOUCHED=1
fi
done
if [ $TOUCHED ]
then
echo "Pricedb file at $LEDGER_PRICEDB was modified."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment