diff options
Diffstat (limited to 'bitcoin')
-rwxr-xr-x | bitcoin/btc_ticker.sh | 46 |
1 files changed, 46 insertions, 0 deletions
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 |