ahoy all, im trying to make a bitcoin value ticker and display it on the Scroll pHAT HD…
this gets the value in dollars in the format 1234.56 but im wondering how to add 17 pixels to the end of the string so it scrolls off the screen and doesn’t just get cleared by the function (detect the string length then loop it?)
anyone got ideas? :)
#!/usr/bin/env python
import time
import signal
import unicodedata
import scrollphathd
from scrollphathd.fonts import font5x5
from time import sleep
import json
#import requests, json
import urllib
# choose currencies to display
currencies = ['btcusd']
#Uncomment to rotate the text
#scrollphathd.rotate(180)
while True:
string = ''
for currency in currencies:
url = 'https://www.bitstamp.net/api/v2/ticker/%s/' % currency
#print(url)
data = json.load(urllib.urlopen(url))
string += '%s' % data['last'] + ' '
for i in range(10):
scrollphathd.clear()
#print(string)
buffer = scrollphathd.write_string(string, x=17, y=0, font=font5x5, brightness=0.2, monospaced=False)
for c in range(buffer):
scrollphathd.show()
scrollphathd.scroll(1)
time.sleep(0.05)
sleep(10)
if it is trimming your spaces from the end of the string maybe add a divider char like | or - at the end to prevent it and pad the beginning so it spaces evenly
Oh, that was the problem. I have to open it manually via Python 2, it would open with Thonny python if I just execute the script.
This is all pretty confusing for me. How can I get it to automatically run in python 2?