X-Git-Url: http://git.treefish.org/~alex/bitvalue.git/blobdiff_plain/a9f0a831d339323f2c8aa87b1005f252e4178eb6..a78f46a80b4c2f94f7bbaa6f4cd3e3d262ef1766:/bitvalue?ds=sidebyside diff --git a/bitvalue b/bitvalue index f2bb53c..4445017 100755 --- a/bitvalue +++ b/bitvalue @@ -1,9 +1,39 @@ #!/bin/bash CONFIG=~/.bitvaluerc +HOST=data.bitcoinity.org + +TIMESPAN="24h" + +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 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 + ;; + esac +done +shift $((OPTIND - 1)) if [ ! -f $CONFIG ]; then cat << EOF > $CONFIG +EXCHANGE="bitstamp" CURRENCY="EUR" ZERO_RATE="1" ZERO_VALUE="1" @@ -13,18 +43,24 @@ fi source $CONFIG -if [ ! -z "$1" ]; then - TIMESPAN="$1" -else - TIMESPAN="30d" +if ! ping -c 1 $HOST >/dev/null 2>&1; then + echo "Host $HOST is unreachable!" + exit 1 fi -cat << EOF | gnuplot +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 "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×pan=$TIMESPAN\"" \ +set title "EXCHANGE: $EXCHANGE | TIMESPAN: $TIMESPAN\nZERO RATE: $ZERO_RATE $CURRENCY | ZERO VALUE: $ZERO_VALUE $CURRENCY" +plot "< wget -q -O - \"https://$HOST/export_data.csv?currency=$CURRENCY&data_type=price&exchange=$EXCHANGE&t=l×pan=$TIMESPAN\"" \ using 1:(\$3/$ZERO_RATE*$ZERO_VALUE) with lines title "" EOF + +if [ $? -ne 0 ]; then + echo "Error while preparing data!" >&2 + exit 1 +fi + +exit 0