summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2013-05-05 14:55:22 +0200
committerYves Fischer <yvesf-git@xapek.org>2013-05-05 14:55:22 +0200
commit3412f6537cc27f10644b67cd50f757016925b5e7 (patch)
tree6eb43f1293c6daff6c56c12d44704cd034629c91
parent38246345be649148a3e07b414e3e7ca50700c338 (diff)
downloadscripts-3412f6537cc27f10644b67cd50f757016925b5e7.tar.gz
scripts-3412f6537cc27f10644b67cd50f757016925b5e7.zip
btc-ticker
-rwxr-xr-xbitcoin/btc_ticker.sh46
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