W. Wang
W. Wang

Reputation: 33

tweepy streaming track filter results

It seems not all the tweets I get using filter contain the item ("health" in this case). How could I get only tweets contain this specific item? Anyone can help me? Thanks so much in advance!!

This is the line when I use filter: sapi.filter(locations=[-79.55, 37.883, -75.067, 39.717],track = ["health"])

Upvotes: 1

Views: 1190

Answers (2)

shoyab khan
shoyab khan

Reputation: 1

It is very easy you just need to add this line in your code.

twitterStream.filter(track=["health"])

Upvotes: 0

dbernard
dbernard

Reputation: 561

Unfortunately, the Streaming API does not allow filtering by both location and terms. From the docs:

Bounding boxes do not act as filters for other filter parameters. For example track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area.

So essentially the reason you are seeing some tweets that do not contain the word "health" is because you are receiving tweets containing the word "health", OR located within your bounding box (in this case, locations=[-79.55, 37.883, -75.067, 39.717]).

You can, however, try to filter by your term(s) then parse through the tweet data for the location, or alternately filter by location then search the tweet text for your term(s). I would probably suggest the latter if location is necessary to limit the scope of your tweet consumption.

Upvotes: 1

Related Questions