bean-prices 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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. bean-price -e "USD:oanda/${COMMODITY}_USD" | sed -e 's/_USD//' | awk -e '{printf "%s %s %s %.2f %s\n", $1, $2, $3, $4, $5}' | tee -a ${TEMP_FILE}
  17. elif [ $TYPE == 'f' ] ; then
  18. bean-price -e "USD:google/MUTF:${COMMODITY}" | sed -e 's/MUTF://' | awk -e '{printf "%s %s %s %.2f %s\n", $1, $2, $3, $4, $5}' | tee -a ${TEMP_FILE}
  19. else
  20. echo "$TYPE is not currently a known type."
  21. fi
  22. done
  23. cat ${TEMP_FILE} >> ~/.ledger/prices.beancount
  24. CWD=$(pwd)
  25. cd ~/.ledger/
  26. git add prices.beancount
  27. git commit -m "Updated beancount price database."
  28. cd ${CWD}