eggman
eggman

Reputation: 423

Tweepy performing search only on letters not whole word

If anyone has much experience with Tweepy some help would be greatly appreciated. I am writing a GUI app that takes user input through a Tkinter Entry widget to filter which tweets are returned.

I have a listener class that is implemented as specified on the Tweepy docs with the addition of this, which simply adds the tweet text to a defined tweet_box which is a Text widget to display the tweets.

def on_data(self, data):
    tweet = json.loads(data)          
    tw = tweet['text']
    tweet_box.insert(tk.END, tw)
    tweet_box.insert(tk.END, "\n")
    tweet_box.see(tk.END)
    time.sleep(2)
    return True  

I am then filtering the tweets using this;

 auth = OAuthHandler(consumer_key, consumer_secret)
 auth.set_access_token(access_token, access_secret)
 self.listener = TwListener()
 streamer = Stream(auth, self.listener)
 streamer.filter(track=self.search_field.get())

The search_field.get() method is coming from a Entry widget where the user inputs the term to filter by.

So my understanding is whatever is in the search_field, when calling the .get() method, you should be able to return that value for use. And in testing, just printing out said value - it works. However when it goes into the tweepy wrapper for the filter it does not appear to take the whole value in, rather it appears to be performing a search on a By-letter basis. As in, if the user were to input 'Python', it would search for P or Y or T etc.

I really can't seem to understand why this is happening, has anyone had a similar experience?

Upvotes: 0

Views: 69

Answers (1)

Dan D.
Dan D.

Reputation: 74655

Streaming With Tweepy states:

"The track parameter is an array of search terms to stream."

Your code should wrap the single string in a list like this:

streamer.filter(track=[self.search_field.get()])

Upvotes: 2

Related Questions