Browse Source

And here's the new one!

Samuel W. Flint 6 years ago
parent
commit
1f23b0617b
1 changed files with 32 additions and 0 deletions
  1. 32 0
      bean-prices

+ 32 - 0
bean-prices

@@ -0,0 +1,32 @@
+#!/bin/sh
+
+IFS="
+"
+
+TEMP_FILE=$(mktemp)
+
+echo '' | tee -a ${TEMP_FILE}
+date +'* %Y-%m-%d' | tee -a ${TEMP_FILE}
+echo '' | tee -a ${TEMP_FILE}
+
+for line in $(cat ~/.ledger/commodities.txt ) ; do
+    TYPE=$(echo $line | cut -d' ' -f1)
+    COMMODITY=$(echo $line | cut -d' ' -f2)
+    if [ $TYPE == 'c' ] ; then
+        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}
+    elif [ $TYPE == 's' ] ; then
+        bean-price -e "USD:google/$COMMODITY" | awk -e '{printf "%s %s %s %.2f %s\n", $1, $2, $3, $4, $5}'  | tee -a ${TEMP_FILE}
+    elif [ $TYPE == 'm' ] ; then
+        echo "Precious metals are not currently supported."
+    else
+        echo "$TYPE is not currently a known type."
+    fi
+done
+
+cat ${TEMP_FILE} >> ~/.ledger/prices.beancount
+
+CWD=$(pwd)
+cd ~/.ledger/
+git add prices.beancount
+git commit -m "Updated beancount price database."
+cd ${CWD}