]> git.treefish.org Git - bitvalue.git/blobdiff - bitvalue
do not use https
[bitvalue.git] / bitvalue
index 7ae88887f93f03bb31773c6dfef60ac41e2e7ab6..0483eb18e19075429acfc2fa41ce63b6883f0a0d 100755 (executable)
--- a/bitvalue
+++ b/bitvalue
@@ -1,31 +1,32 @@
 #!/bin/bash
 
 CONFIG=~/.bitvaluerc
+HOST=data.bitcoinity.org
 
 TIMESPAN="24h"
 
-USAGE="Usage: $(basename "$0") [-h] [-t val]
+USAGE="Usage: $(basename "$0") [-h] [-t 10m|1h|24h|3d|7d|30d|6m|2y|5y|all]
 Simple bash script to visualize the value of your bitcoin investment.
 
 Arguments:
   -h  show this help text
-  -t  set the timespan (default: $TIMESPAN)"
+  -t  used 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
-           ;;
+        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))
@@ -34,20 +35,37 @@ if [ ! -f $CONFIG ]; then
     cat << EOF > $CONFIG
 EXCHANGE="bitstamp"
 CURRENCY="EUR"
-ZERO_RATE="1"
-ZERO_VALUE="1"
+BTC="1"
 EOF
     echo "Created config: $CONFIG - Adapt config parameters!"
 fi
 
 source $CONFIG
 
-cat << EOF | gnuplot
+URL="http://$HOST/export_data.csv?\
+currency=$CURRENCY&\
+data_type=price&\
+exchange=$EXCHANGE&\
+t=l&\
+timespan=$TIMESPAN"
+
+if ! wget -S --spider $URL 2>&1 | grep 'HTTP/1.1 200 OK' >/dev/null; then
+    echo "Can not retrieve data from $HOST!";
+    exit 1
+fi
+
+cat << EOF | gnuplot 2>/dev/null
 set terminal dumb
 set datafile separator ","
 set xdata time
 set timefmt "%Y-%m-%d %H:%M:%S UTC"
-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 ""
+set title "EXCHANGE: $EXCHANGE | TIMESPAN: $TIMESPAN\nCURRENCY: $CURRENCY | BTC: $BTC "
+plot "< wget -q -O - \"$URL\"" using 1:(\$3*$BTC) with lines title ""
 EOF
+
+if [ $? -ne 0 ]; then
+    echo "Error while preparing data!" >&2
+    exit 1
+fi
+
+exit 0