-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpriceDisplay.py
More file actions
67 lines (55 loc) · 1.87 KB
/
priceDisplay.py
File metadata and controls
67 lines (55 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from sense_hat import SenseHat
sense = SenseHat()
from urllib2 import urlopen
import json
import time
#Low Light Toggle: set your sense-hat's display to low brightness
sense.low_light = False #True
#Rotation Toggle
sense.set_rotation(180)
TEMP_ETH = 0
TEMP_BTC = 0
while True:
try:
#Connecting to Poloniex's API
url = urlopen('https://poloniex.com/public?command=returnTicker').read()
result = json.loads(url)
#Reading the last price for our coins
ETH = result['BTC_ETH']['last']
BTC = result['USDT_BTC']['last']
BTC = round(float(BTC),2)
#Converting ETH price in USD
ETH_USD = float(BTC) * float(ETH)
ETH_USD = round(float(ETH_USD),2)
#Storing the price for later use
ETH_OLD = TEMP_ETH
BTC_OLD = TEMP_BTC
print('ETH: $'+ str(ETH_USD))
print('BTC: $'+ str(BTC))
#Changing the color of the text
#Green when the price rises, yellow when it stays the same
#and red when it decreses
#Display the prices on SENSE-HAT for ETH.
if ETH_USD > ETH_OLD :
sense.show_message("ETH: $" + str(ETH_USD), text_colour=[0,255,0])
elif ETH_USD == ETH_OLD :
sense.show_message("ETH: $" + str(ETH_USD), text_colour=[255, 255, 0])
else :
sense.show_message("ETH: $" + str(ETH_USD), text_colour=[255, 51, 51])
#Display the prices on SENSE-HAT for BTC.
if BTC > BTC_OLD :
sense.show_message("BTC: $" + str(BTC), text_colour=[0,255,0])
elif BTC == BTC_OLD :
sense.show_message("BTC: $" + str(BTC), text_colour=[255, 255, 0])
else :
sense.show_message("BTC: $" + str(BTC), text_colour=[255, 51, 51])
#Printing the stored values to console
print('ETH_OLD: $'+ str(ETH_OLD))
print('BTC_OLD: $'+ str(BTC_OLD))
print('--------------------------')
TEMP_ETH = ETH_USD
TEMP_BTC = BTC
time.sleep(3)
except:
sense.show_message("failed to retrieve feed")
time.sleep(3)