bean-prices 967 B

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/sh
  2. IFS="
  3. "
  4. TEMP_FILE=$(mktemp)
  5. echo '' | tee -a ${TEMP_FILE}
  6. date +'* %Y-%m-%d' | tee -a ${TEMP_FILE}
  7. echo '' | tee -a ${TEMP_FILE}
  8. for line in $(cat ~/.ledger/commodities.txt ) ; do
  9. TYPE=$(echo $line | cut -d' ' -f1)
  10. COMMODITY=$(echo $line | cut -d' ' -f2)
  11. if [ $TYPE == 'c' ] ; then
  12. bean-price -e "USD:google/^CURRENCY:USD$COMMODITY" | sed -e 's/CURRENCY:USD//' | awk -e '{printf "%s %s %s %.2f %s\n", $1, $2, $3, $4, $5}' | tee -a ${TEMP_FILE}
  13. elif [ $TYPE == 's' ] ; then
  14. bean-price -e "USD:google/$COMMODITY" | awk -e '{printf "%s %s %s %.2f %s\n", $1, $2, $3, $4, $5}' | tee -a ${TEMP_FILE}
  15. elif [ $TYPE == 'm' ] ; then
  16. echo "Precious metals are not currently supported."
  17. else
  18. echo "$TYPE is not currently a known type."
  19. fi
  20. done
  21. cat ${TEMP_FILE} >> ~/.ledger/prices.beancount
  22. CWD=$(pwd)
  23. cd ~/.ledger/
  24. git add prices.beancount
  25. git commit -m "Updated beancount price database."
  26. cd ${CWD}