]> git.treefish.org Git - bitvalue.git/blobdiff - bitvalue
Default to timespan of 24 hours
[bitvalue.git] / bitvalue
index f2bb53cd02923558551bb93501ff38ec5c2c5520..7ae88887f93f03bb31773c6dfef60ac41e2e7ab6 100755 (executable)
--- a/bitvalue
+++ b/bitvalue
@@ -2,8 +2,37 @@
 
 CONFIG=~/.bitvaluerc
 
+TIMESPAN="24h"
+
+USAGE="Usage: $(basename "$0") [-h] [-t val]
+Simple bash script to visualize the value of your bitcoin investment.
+
+Arguments:
+  -h  show this help text
+  -t  set the timespan (default: $TIMESPAN)"
+
+while getopts ':ht:' option; do
+    case "$option" in
+       h) echo "$USAGE"
+          exit
+          ;;
+       t) TIMESPAN=$OPTARG
+          ;;
+       :) printf "missing argument for -%s\n" "$OPTARG" >&2
+          echo "$usage" >&2
+          exit 1
+          ;;
+       \?) printf "illegal option: -%s\n" "$OPTARG" >&2
+           echo "$usage" >&2
+           exit 1
+           ;;
+    esac
+done
+shift $((OPTIND - 1))
+
 if [ ! -f $CONFIG ]; then
     cat << EOF > $CONFIG
+EXCHANGE="bitstamp"
 CURRENCY="EUR"
 ZERO_RATE="1"
 ZERO_VALUE="1"
@@ -13,18 +42,12 @@ fi
 
 source $CONFIG
 
-if [ ! -z "$1" ]; then
-    TIMESPAN="$1"
-else
-    TIMESPAN="30d"
-fi
-
 cat << EOF | gnuplot
 set terminal dumb
 set datafile separator ","
 set xdata time
 set timefmt "%Y-%m-%d %H:%M:%S UTC"
-set title "TIMESPAN: $TIMESPAN | ZERO RATE: $ZERO_RATE $CURRENCY | ZERO VALUE: $ZERO_VALUE $CURRENCY"
-plot "< wget -q -O - \"https://data.bitcoinity.org/export_data.csv?currency=$CURRENCY&data_type=price&exchange=bitstamp&t=l&timespan=$TIMESPAN\"" \
+set title "EXCHANGE: $EXCHANGE | TIMESPAN: $TIMESPAN\nZERO RATE: $ZERO_RATE $CURRENCY | ZERO VALUE: $ZERO_VALUE $CURRENCY"
+plot "< wget -q -O - \"https://data.bitcoinity.org/export_data.csv?currency=$CURRENCY&data_type=price&exchange=$EXCHANGE&t=l&timespan=$TIMESPAN\"" \
      using 1:(\$3/$ZERO_RATE*$ZERO_VALUE) with lines title ""
 EOF