Skip to content

Instantly share code, notes, and snippets.

@mitchas
Last active May 9, 2019 17:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mitchas/aa03c5b18f25b329ec442c0997d21a9f to your computer and use it in GitHub Desktop.
Save mitchas/aa03c5b18f25b329ec442c0997d21a9f to your computer and use it in GitHub Desktop.
Bitcoin price checker for Pimoroni Four Letter Phat / Raspberry Pi
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