Conky Python Mt.Gox Ticker

The python script is as follows (or see attached source):

#! /usr/bin/env python
#coding: utf-8
#Adercon Consulting (adercon.com). This code may be reused at will but please leave this attribution intact.

import urllib2,datetime
import json as simplejson

#variables.
data_source = 'https://data.mtgox.com/api/2/BTCUSD/money/ticker'
date_format = '%Y-%m-%d %H:%M:%S'
out_sep = ' | '
app_name = 'MT.GOX Ticker'
app_version = '1.0.0'
#get.
req = urllib2.Request(data_source, None, {'user-agent':'text/json'})
opener = urllib2.build_opener()
f = opener.open(req)
data = simplejson.load(f)   #deserialize
#process.
price = data['data']['last_all']['display_short']
high = data['data']['high']['display_short']
low = data['data']['low']['display_short']
volume = data['data']['vol']['display_short'].replace(u'\xa0',' ')   #re-encode space character for utf-8
asof = datetime.datetime.fromtimestamp(int(data['data']['now'][:10])).strftime(date_format)
#print.
print app_name+' @'+asof+ \
    '\n Now: '+price+' (vol: '+volume+')'+ \
    '\n   high: '+high+out_sep+'low: '+low

This script can be called from conky as follows:

${texeci 60 ~/scripts/mtgox_ticker.py}

The above uses threaded execi to call the mtgox_ticker.py script every 60 seconds.

The results will be similar to the following:

MT.Gox Ticker Example