Bitcoin Value Ticker for Scroll pHAT HD


#1

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)

#2

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

something like
string += ' ' + '%s' % data['last'] + ' -'

to get something like

' string - string2 - string3 -'


#3

Thanks for the reply, it seems to ignore the buffer length and wrap the
text prematurely. I’ll do some traces once I’ve kicked this cold 😷


#4

Ahoy Mr-G, sorry for pirating your topic. I tried out your script, but when I run it I get the the following error:

AttributeError: module ‘urllib’ has no attibute ‘urlopen’.

Can you help me out?


#5

hey @jv13 i’ve placed the latest script at https://github.com/MrGJones/hello-crypto


#6

download

  • bitcoin_wiv_logo.py
  • font5x5_numbers.py
  • btc_logo_circle.png
  • btcshuttle.png

and try running the bitcoin_wiv_logo.py script


#7

I cloned the whole repository but and run the script but still get errors.

ImportError: No module named ‘urllib2’

for bitcoin_wiv_logo.py

and

attributeError: module ‘urllib’ has no attribute ‘urlopen’

for hello-btc


#8

Are you running this in python 2?


#9

No python 3.5 I think


#10

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?


#11

i just right click it and open it in the IDLE ide atm… tbh im a noob at
all this stuff :)