Skip to content

Instantly share code, notes, and snippets.

@danielfl
Created January 12, 2017 13:27
Show Gist options
  • Save danielfl/f3deeb38994cd2effa2c54147348eb98 to your computer and use it in GitHub Desktop.
Save danielfl/f3deeb38994cd2effa2c54147348eb98 to your computer and use it in GitHub Desktop.
At i3blocks: [btc] command=$HOME/.i3/i3-btcprice.py interval=1 separator=false
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import urllib2
import json
last_price=10.0
ml="-"
def get_data2(web_site_api, currency_name):
global last_price
global ml
pric=0
ml="↑"
webdata = urllib2.urlopen(web_site_api).read()
decodejson = json.loads(webdata)
last_price=float(decodejson['ticker']['last'])
webdata = urllib2.urlopen(web_site_api).read()
decodejson = json.loads(webdata)
pric=float(decodejson['ticker']['last'])
if pric < last_price:
ml="↓"
print time.strftime('%X',time.localtime(time.time())) + " %4.0f%sCNY" % (pric,ml)
#main
if __name__ == "__main__":
try:
get_data2("https://www.okcoin.com/api/ticker.do?symbol=btc_cny", "BTC") #btc/cny
except:
print time.strftime('%X',time.localtime(time.time())) + " ---- CNY"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment