bean-prices 1.5 KB

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