bean-prices 1.3 KB

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