Last active
May 9, 2019 17:24
-
-
Save mitchas/aa03c5b18f25b329ec442c0997d21a9f to your computer and use it in GitHub Desktop.
Bitcoin price checker for Pimoroni Four Letter Phat / Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import string | |
from random import randint | |
import random | |
import fourletterphat as flp | |
import urllib2 | |
import json | |
# String of numbers for display to cycle while loading. Can be any letters/numbers. It's random. | |
numbers = "1234567890" | |
while True: | |
# End time - number at end (2) is seconds for loading screen (random numbers) to show | |
t_end = time.time() + 2 | |
while time.time() < t_end: | |
flp.clear() | |
flp.set_digit(0, random.choice(numbers)) | |
flp.set_digit(1, random.choice(numbers)) | |
flp.set_digit(2, random.choice(numbers)) | |
flp.set_digit(3, random.choice(numbers)) | |
flp.show() | |
# Sleep for 0.05 seconds before choosing more random numbers | |
time.sleep(0.05) | |
flp.clear() | |
data = urllib2.urlopen("https://www.bitstamp.net/api/ticker").read() | |
dataJSON = json.loads(data) | |
price = dataJSON["last"] | |
# Convert full number to XX.Xk | |
flp.set_digit(0, price[0]) | |
flp.set_digit(1, price[1]) | |
flp.set_digit(2, price[2]) | |
# Display "K" (thousand) as 4th digit | |
flp.set_digit(3, "K") | |
# Show decimal | |
flp.set_decimal(1, True) | |
flp.show() | |
# Sleep for 500 seconds, then refresh it all | |
time.sleep(500) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment