Quantcast
Channel: Pimoroni Buccaneers - Latest posts
Viewing all articles
Browse latest Browse all 54410

Twitter #hashtag to scroll pHAT

$
0
0

I think that the scrollphat.buffer_length() isn't being calculated quite correctly, but the code below works for me and fixes the problem with the scrolling continuing too long and looping back to the chevrons as you saw. Let me know how you get on with this.

import sys
import time
import tweepy
import scrollphat

scrollphat.clear()

while True:
    try:
        scrollphat.set_brightness(2)

        class MyStreamListener(tweepy.StreamListener):
            def on_status(self, status):
                if not status.text.startswith('RT'):
                    scroll_tweet(status)
            def on_error(self, status_code):
                if status_code == 420:
                    return False

        def scroll_tweet(status):
            status = '     >>>>>     @%s: %s     ' % (status.user.screen_name.upper(), status.text.upper())
            status = status.encode('ascii', 'ignore').decode('ascii')
            scrollphat.write_string(status)
            status_length = scrollphat.buffer_len()
            while status_length > 0:
                scrollphat.scroll()
                time.sleep(0.1)
                status_length -= 1

        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=['#raspberrypi'], async=False)

    except KeyboardInterrupt:
        scrollphat.clear()
        sys.exit(-1)

Viewing all articles
Browse latest Browse all 54410