Twitter #hashtag to scroll pHAT

hi Phil, many thanks for your input.
it can be asynchronous! but that’s set to false at the moment, http://docs.tweepy.org/en/v3.4.0/streaming_how_to.html as per sandys tutorial.
your FIFO suggestion looks ideal, this is just what i think it needs! i will take a look into implementing this soon but i’m afraid my time over the next couple of weeks is taken up designing various print works.

theres some strange quirks with the program which seem to freeze the system/scroller momentarily but now with the HD supported at least its heading in the right direction :)

thanks again for your input!
Glenn

hi phil. i’ve managed to get the tweets going into the fifo queue now, many thanks for the tips!

also made a mainloop but i cant seem to get it to scroll though, any ideas? :)

#!/usr/bin/env python

import sys
import time
import tweepy
import scrollphathd
import Queue
from scrollphathd.fonts import font5x7smoothed

scrollphathd.clear()

#make FIFO queue
q = Queue.Queue()

#define main loop to fetch formatted tweet from queue
def mainloop():
    while not q.empty():
        status = q.get()
        scrollphathd.write_string(status,font=font5x7smoothed, brightness=0.1)            
        status_length = scrollphathd.write_string(status, x=0, y=0,font=font5x7smoothed, brightness=0.1)
        #print(status)
        print status
        #print 'status length --->',status_length
        while status_length > 0:
            #print 'status length',status_length
            #print 'buffer_len',scrollphathd.write_string(status, x=0, y=0,font=font5x7smoothed, brightness=0.1)
            #scrollphathd.flip(x=True)
            scrollphathd.rotate(degrees=180)                    
            scrollphathd.show()
            scrollphathd.scroll(1)
            status_length -= 1
            time.sleep(0.01)
        else:
            #scrollphathd.scroll(0)
            #print '>>status length is zero<<'
            scrollphathd.clear()
            #scrollphathd.show()        

while True:
    try:
        class MyStreamListener(tweepy.StreamListener):
            def on_status(self, status):
                if not status.text.startswith('RT'):
                    #scroll_tweet(status)
                    #format the incoming tweet string
                    status = '     >>>>>     @%s: %s     ' % (status.user.screen_name.upper(), status.text.upper())
                    status = status.encode('ascii', 'ignore').decode('ascii')  
                    # put tweet into the fifo queue
                    q.put(status)
                    #print q.get()
            def on_error(self, status_code):
                if status_code == 420:
                    return False

        #def scroll_tweet(status):                   
                            
        consumer_key =
        consumer_secret =

        access_token = 
        access_token_secret = 

        #scrollphathd.write_string("Loading Tweets")
        #scrollphathd.scroll()
        #time.sleep(0.1)

        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_token, access_token_secret)
        api = tweepy.API(auth)

        myStreamListener = MyStreamListener()
        myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener)

        myStream.filter(track=['hug'], stall_warnings=True)
       
    except KeyboardInterrupt:
        scrollphathd.clear()
        sys.exit(-1)

root.mainloop()

ok here’s the latest code, saving and reading from the fifo queue and also scrolling ok now.

we be scrollin, scrollin, scrollin…

#!/usr/bin/env python

import sys
import time
import tweepy
import scrollphathd
import Queue
from scrollphathd.fonts import font5x7smoothed

# scrollphathd.clear()

#make FIFO queue
q = Queue.Queue()

#define main loop to fetch formatted tweet from queue
def mainloop():
    while True:
        # not q.empty():
        status = q.get()
        scrollphathd.write_string(status,font=font5x7smoothed, brightness=0.1)
        status_length = scrollphathd.write_string(status, x=0, y=0,font=font5x7smoothed, brightness=0.1)
        #print(status)
        #print ("<<<<<< Scrolling tweet", status)
        time.sleep(0.25)
        #print 'status length --->',status_length
        while status_length > 0:
             #print 'status length',status_length
             #print 'buffer_len',scrollphathd.write_string(status, x=0, y=0,font=font5x7smoothed, brightness=0.1)
             #scrollphathd.flip(x=True)
             scrollphathd.rotate(degrees=180)
             scrollphathd.show()
             scrollphathd.scroll(1)
             status_length -= 1
             time.sleep(0.01)
        else:
             #scrollphathd.scroll(0)
             #print ">>status length is zero<<"
             scrollphathd.clear()
             #scrollphathd.show()

# while True:

class MyStreamListener(tweepy.StreamListener):
    def on_status(self, status):
        if not status.text.startswith('RT'):
            #scroll_tweet(status)
            #format the incoming tweet string
            status = '     >>>>>     @%s: %s     ' % (status.user.screen_name.upper(), status.text.upper())
            status = status.encode('ascii', 'ignore').decode('ascii')
            # put tweet into the fifo queue
            q.put(status)
            #print ("**tweet saved**", status)
            #print q.get()
    def on_error(self, status_code):
        if status_code == 420:
            return False

consumer_key =''
consumer_secret =''

access_token = ''
access_token_secret = ''

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener)

myStream.filter(track=['hug'], stall_warnings=True, async=True)


try:
    mainloop()
except KeyboardInterrupt:
    print('exit')
    myStream.disconnect()
    sys.exit(-1)
1 Like

That’s a really nice, and well architected (in my humble opinion anyway) example. Are you up for submitting it in a PR to the Scroll pHAT HD GitHub repo?

How do you find font5x7smoothed? I never used it in an example since I thought it looked terrible, but it might fare better when scrolling.

hi phil thanks, sure thing! the smoothed font is ok scrolling but the normal one is clearer for most uses imo… i was just trying it out really!
ill submit it as soon as i work out how to do that! :)

Brilliant will have to try it later. Well done :)

1 Like

hey phil. unsure if it did it right but I’ve made a github repo with this project and did a pull request? can you check?

@Mr-G I can’t see an incoming PR for it? Did I (or someone else) merge it already?

ok forked the pimoroni scroll-phat-hd repo then added my
hashtagtoscrollphathd.py file to examples. unsure if this is correct and i
also need to add some comments :)

Hi, i used this code and still the same problem with scrollhathd examples twitterhashtag

if i tweet #bot_multi i see only 2 :: nothing more

Yea I have exactly the same issue. I was starting to think it was just me

i dont found any solution…

same here, I have been trying all sorts
checking my keys and Tokens, different keywords, checking for possible case sensitive issues. but nothing has worked.

I ultimately want to change the code to scroll every Twitter notification I get "including RT’s " but If I cant even get this working its not looking hopeful. lol

nice… first time i think something at the formatting but idk now

Have you guys tried this one thats included in the scrollphathd examples ?

1 Like

ofc i used this and not works i see only 2 :: and i tryed this one at the forum and same result

yea same here, I just get 2 or 3 :: sometimes followed by a .
but no text displayed.

thanks for your help

i hope someone can fix this problem :)

Firstly, massive thanks for making this script. I spent so long tinkering about trying to make my own and yours worked first time!

I was just wondering if there is something simple I could add into the code so it scrolled the last message found on repeat until a new message is received. I was hoping to use it like a notifications board but unless someone happens to be there when I send the tweet all they would see is a blank screen.

Kind regards,

Alex

1 Like

I had the same problem and spent some time trying out changes to the code. At the end what worked is changing the font from “font5x7smoothed” to “font5x7”.