#!/usr/bin/python
 
from Adafruit_CharLCDPlate import Adafruit_CharLCDPlate
from subprocess import *
from time import sleep, strftime
from datetime import datetime
 
import json
import urllib2
import time
 
lcd = Adafruit_CharLCDPlate()
lcd.begin(16,1)
 
#Function that checks balance of a particular address
def balancecheck():
        balancequery = json.load(urllib2.urlopen("https://blockchain.info/q/addressbalance/1MaUURRXnWtPaRC4wSuBfEMBsBGuw64Thp")) #Address with 0.03BTC for testing
        formatted = (balancequery / 100000000) #Returns result as BTC, not satoshi.
        return formatted
 
#############################
def bitstamp():
        api = json.load(urllib2.urlopen('https://www.bitstamp.net/api/ticker/'))
        current_price = api["last"]
        return current_price
 
def btce():
        api = json.load(urllib2.urlopen('https://btc-e.com/api/2/btc_usd/ticker'))
        current_price = api["ticker"]["last"]
        return current_price
#############################
 
while 1:
        lcd.clear()
        price = bitstamp()
        time = datetime.now().strftime( '%F %H:%M\n' )
        lcd.message(time)
        lcd.message("BTC/USD: " + price)
        sleep(30)