From 3412f6537cc27f10644b67cd50f757016925b5e7 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sun, 5 May 2013 14:55:22 +0200 Subject: btc-ticker --- bitcoin/btc_ticker.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 bitcoin/btc_ticker.sh (limited to 'bitcoin') diff --git a/bitcoin/btc_ticker.sh b/bitcoin/btc_ticker.sh new file mode 100755 index 0000000..189bd26 --- /dev/null +++ b/bitcoin/btc_ticker.sh @@ -0,0 +1,46 @@ +#!/bin/sh +get_key() { + echo $1 | sed -ne 's/^.*"\([a-zA-Z0-9_]\+\)":.*$/\1/p' +} +get_value() { + echo $1 | sed -ne 's/^.*"[^"]\+":"\?\([A-Za-z0-9$\.]*\)"\?$/\1/p' + echo $1 | sed -ne 's/^.*"[^"]\+":{$/{/p' +} + +parse_json() { + local path=$1 + + while read line; do + if [ "$line" = "{" ]; then continue; fi + if [ "$line" = "}" ]; then + return; + fi + + key=`get_key "$line"` + value=`get_value "$line"` + if [ -z "$key" ] || [ -z "$value" ]; then + echo "skip $line" >&2 + continue + fi + if [ "$value" = "{" ]; then + parse_json "${path}_${key}" + else + printf "%s_%s=\"%s\"\n" $path $key $value + fi + done +} + +preprocess_json() { + sed -e 's/}/\n}/g' | sed -e 's/\("[^"]\+":\)/\n\1/g' | tr -d ',' | sed -e 's/\\u/\\\\u/g' +} + +eval $(curl -s --max-time 3 "http://data.mtgox.com/api/2/BTCEUR/money/ticker" | preprocess_json | parse_json "ticker") + +if [ "$ticker_result" = "success" ]; then + echo -n "฿" + echo -n " ➘ $ticker_data_sell_value $ticker_data_sell_currency" + echo -n " ➚ $ticker_data_buy_value $ticker_data_buy_currency" + echo -n " ⋀ $ticker_data_high_value $ticker_data_high_currency" + echo -n " ⋁ $ticker_data_low_value $ticker_data_low_currency" + echo +fi -- cgit v1.2.1