4

I am using statuses/filter and am trying to filter the tweets from the twitter stream based on the parameter "filter_level".

query = ["Donald Trump","Cristiano Ronaldo"]

numberOfTweets = 1000
dictOfTweets ={}
twitter_api = oauth_login()
twitter_stream = twitter.TwitterStream(auth=twitter_api.auth)

for q in query:
  stream =  twitter_stream.statuses.filter(track=q,max_count=numberOfTweets,languages= ['en'],filter_level=['medium'])
  for tweet in stream:
      if tweet.get('text',0) == 0:
          continue
      dictOfTweets.setdefault(q,[]).append(tweet['text'])

I am still getting tweets with filter_level ="low". It would be really helpful if anyone can suggest what am I missing or doing wrong?

madhead
  • 31,729
  • 16
  • 153
  • 201
anon
  • 367
  • 1
  • 4
  • 18

1 Answers1

0

You need to put (languages= ['en'],filter_level=['medium']) while Authentication

query = ["Donald Trump","Cristiano Ronaldo"]

numberOfTweets = 1000
dictOfTweets ={}
twitter_api = oauth_login()
twitter_stream = twitter.TwitterStream(auth=twitter_api.auth, ,languages= ['en'],filter_level=['medium'])

for q in query:
  stream =  twitter_stream.statuses.filter(track=q,max_count=numberOfTweets)
  for tweet in stream:
      if tweet.get('text',0) == 0:
          continue
      dictOfTweets.setdefault(q,[]).append(tweet['text'])
Thirumal Alagu
  • 611
  • 5
  • 10
  • this didn't work for me with the `filter_level` parameter as a list with 'medium' in it, but it did work when passed just as a string – Tom Bush Sep 08 '20 at 08:10