tadd better bitcoin ticker; qemu-kvm wrap - scripts - random scripts
git clone git://parazyd.org/scripts.git
Log
Files
Refs
---
commit 5a6eff26d98276c443543419327c4459af3d07e5
parent 477e9a548a07ce4a810765507b8c01969907a875
Author: parazyd 
Date:   Wed, 15 Feb 2017 03:22:19 +0100

add better bitcoin ticker; qemu-kvm wrap

Diffstat:
  D btcticker                           |      42 -------------------------------
  A qemu-kvm                            |       2 ++
  A ticker                              |      52 +++++++++++++++++++++++++++++++

3 files changed, 54 insertions(+), 42 deletions(-)
---
diff --git a/btcticker b/btcticker
t@@ -1,42 +0,0 @@
-#!/usr/bin/env python2
-
-import json
-import sys
-import urllib
-
-## Bitkonan
-## https://bitkonan.com/api/ticker
-
-
-def dump(name, url):
-    ticker = json.load(urllib.urlopen(url))
-
-    print("(*) " + name + " ticker")
-    print("\tLast: " + ticker['last'] + " USD")
-    print("\tHigh: " + ticker['high'] + " USD")
-    print("\tLow: "  + ticker['low']  + " USD")
-    print("\tVolume: " + ticker['volume'] + " BTC\n")
-
-
-def main():
-    try:
-        market = sys.argv[1]
-    except:
-        print("specify a market")
-        exit(1)
-
-    bitkonanurl = "https://bitkonan.com/api/ticker"
-    bitstampurl = "https://www.bitstamp.net/api/ticker/"
-
-    if market == "bitkonan":
-        dump("Bitkonan", bitkonanurl)
-    elif market == "bitstamp":
-        dump("Bitstamp", bitstampurl)
-    elif market == "all":
-        dump("Bitkonan", bitkonanurl)
-        dump("Bitstamp", bitstampurl)
-    else:
-        print("unsupported market")
-        exit(1)
-
-main()
diff --git a/qemu-kvm b/qemu-kvm
t@@ -0,0 +1,2 @@
+#!/bin/dash
+exec qemu-system-x86_64 -enable-kvm $@
diff --git a/ticker b/ticker
t@@ -0,0 +1,52 @@
+#!/bin/sh
+
+jsonurl="http://api.bitcoincharts.com/v1/markets.json"
+
+jsonfile=/tmp/bitcoincharts.json
+
+[ $(stat --format=%Y $jsonfile) -gt $(( $(date +%s) - 900 )) ] || {
+        printf "curling...\n"
+        curl -s "$jsonurl" > "$jsonfile"
+}
+
+parse() {
+        cat $jsonfile | jq \
+                '.[] | select( .symbol | contains("'$1'"))'
+}
+
+market="$1"
+case "$market" in
+        bitstamp)
+                parse bitstampUSD
+                ;;
+        bitkonan)
+                parse bitkonanUSD
+                ;;
+        kraken)
+                parse krakenEUR
+                ;;
+        localbtc)
+                parse localbtcUSD
+                ;;
+        bitfinex)
+                parse bitfinexUSD
+                ;;
+        coincheck)
+                parse coincheckJPY
+                ;;
+        all)
+                cat $jsonfile | jq '.[]'
+                ;;
+        *)
+                cat <