Skip to content

Instantly share code, notes, and snippets.

@l-margiela
Created November 3, 2013 15:06
Show Gist options
  • Save l-margiela/7291181 to your computer and use it in GitHub Desktop.
Save l-margiela/7291181 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import urllib2, json
class _Data:
last = 0
class Py3status:
def __init__(self):
self.DATA=_Data()
self.CURR1="ltc"
self.CURR2="btc"
def get_last(self, json_p3s, i3status_config):
btc_e_json = urllib2.urlopen("https://btc-e.com/api/2/%s_%s/ticker"%(self.CURR1, self.CURR2)).read()
btc_e_json = json.loads(btc_e_json)
last = btc_e_json['ticker']['last']
response = {'full_text': '', 'name':'BTC-E %s/%s exchange'%(self.CURR1.upper(), self.CURR2.upper())}
if last >= 0.015:
response['color'] = i3status_config['color_good']
elif last < 0.01:
response['color'] = i3status_config['color_bad']
response['full_text'] = "%s/%s: %s"%(self.CURR2.upper(), self.CURR1.upper(), str(last))
if self.DATA.last < last:
response['full_text'] += '↑'
else:
response['full_text'] += '↓'
self.DATA.last = last
return (0, response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment