Aventinus
Aventinus

Reputation: 1392

Is it possible to use Tweepy's filter function without the track parameter?

I'm using Tweepy to live stream tweets based on a few parameters.

The following example works fine as it returns all live tweets that include the word 'python':

stream.filter(track=['python'])

However, I would like to get all live tweets while using other ways of filtering my stream, such as the language. For example, the following example should allow me to get all Greek tweets:

stream.filter(track=['*'], languages=['el'])

Unfortunately, this returns all Greek tweets that include the * symbol.

If I type:

stream.filter(languages=['el']) 

I get a 406 error.

So, my questions is:

Can I remove the track parameter to get all live tweets using Tweepy? Is there any other way to get all tweets based on other parameters?


EDIT: I know that stream.sample() is an option. The problem is that if I type:

stream.sample(languages=['en'])

I get a lot of tweets, but if I type:

stream.sample(languages=['el'])

the stream is very slow. I.e., I may get one tweet per minute. I guess this has to do with how the tweets are sampled and how small the sample is. So, I'm asking whether there's a better way to achieve what I want, potentially without using stream.sample().

Upvotes: 3

Views: 435

Answers (1)

Tin Nguyen
Tin Nguyen

Reputation: 5330

stream.filter(follow=follow, track=track, locations=location)

You have to supply follow (list of twitter ids), track (list of keywords) or location boxes location (tweets from a region).
You can supply multiple it will be act as a logical OR.

The logical step would be to specify a location box that covers the whole earth. Sadly this only streams tweets of users that have their geo location information exposed.

So this means all you can really do is something like this:

stream.filter(follow=follow, track=["a", "b", "c", ...], locations=[0, -90, 360, 90], languages=['el'])

The track parameter accepts a list up to 400 keywords. You can search for a list of most commonly used words in your language and supply that there.

Bear in mind you will not get all tweets due to the sheer amount of tweets that are going to arrive in. It'd be like 1% of all tweets and you cannot go lower. You will have to pay to access the premium API.

Upvotes: 1

Related Questions