Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 42 lines (33 sloc) 1010 Bytes
#!/usr/bin/env python
import urllib2
import simplejson
import yaml
import zephyr
import traceback
import sys
# URL = 'https://mtgox.com/code/data/ticker.php'
tickers = [('bitstamp', 'https://www.bitstamp.net/api/ticker/')]
dryrun = (len(sys.argv) > 1 and sys.argv[1] in ['-n', '--dryrun'])
zephyr.init()
for (instance, URL) in tickers:
try:
data = simplejson.loads(urllib2.urlopen(URL).read())
ticker = dict((k,float(v)) for (k,v) in data.items())
display = """\
last: %(last).2f / bid: %(bid).2f / ask: %(ask).2f
low: %(low).2f / high: %(high).2f
volume: %(volume)s""" % ticker
if dryrun:
print "[%s]\n%s" % (instance, display)
continue
z = zephyr.ZNotice()
z.cls = 'bitcoin'
z.instance = instance
z.opcode = 'auto'
z.fields = ['Bitcoin Market Zephyr gateway',
display]
z.auth = False
z.sender = 'bitcoin'
z.send()
except:
traceback.print_exc()