Blinkt! Twitter Monitor - multiple hashtags?


#1

How would the code need to look for Twitter_Monitor.py to flash a different colour for a second hashtag, third hashtag, fourth hashtag etc?

Thank you.


#2

Digging deep into the API docs suggests that a simple comma separated list should work. Try it and see!

AFAIK the Twitter Monitor script isn’t working at all, though, so if it works for you, please let me know!


#3

Well I wouldn’t know where to put comma separated lists, but the current script seems to do something.

The Blinkt! certainly flashes away, whether it’s related to the hashtag in the script, I can’t quite tell, it does seem quite random!!


#4

That’s a good point!

I think you can edit it into this line:

So something like:

twitterstream.filter(track=['#hashtag1,#hashtag2'])

That said, it could potentially accept the syntax:

twitterstream.filter(track=['#hashtag1', '#hashtag2'])

But a quick look at the docs didn’t clarify this :(

For debugging, probably a good idea to change:

class listener(StreamListener):
    def on_data(self, data):
        blink_blinkt()
        return True

to

class listener(StreamListener):
    def on_data(self, data):
        print(data)
        blink_blinkt()
        return True

#5

I could do the
#hashtag1, #hashtag2, #hashtag3
thing, that seems reasonably obvious, even to a code nonce like moi, but they’d all flash the same colour on the Blinkt!.

How would you code them to flash different colours?


#6

Either by creating multiple stream listeners, or by inspecting the incoming tweets for the hashtags and acting accordingly. I’d probably favour the latter since it has fewer potential pitfalls.

Scroll pHAT HD has a good example of a Listener class which looks at the incoming tweet data: