Iryna
Iryna

Reputation: 65

Filtering in tweepy

I am new to tweepy and have encountered a problem. I want to download tweets with special hashtags. But it seems

stream.filter(track = ['word1', 'word2', 'word3']) 

looks for these words in tweet and not in hashtags of the tweet. How can I filter on hashtags?

Upvotes: 4

Views: 8997

Answers (2)

dbernard
dbernard

Reputation: 561

You can actually filter tweets based on your special hashtag.

stream.filter(track=['#MySpecialHashtag', '#AlsoThisHashtag'])

This will pick up only tweets that contain the hashtags you provide as part of the tweet text and save you from arbitrarily collecting tweets and checking if the hashtag field has your hashtag in it.

Upvotes: 12

aberna
aberna

Reputation: 5814

You find the tags in the status object. It is there you have to make the comparison with the ones you are looking for.

example:

for hashtag in status.entities['hashtags']:
    print(hashtag['text'])

example here: http://www.pythoncentral.io/introduction-to-tweepy-twitter-for-python/

Upvotes: -2

Related Questions