how to get English tweets alone using python?

Viewed 5918

Here is my current code

from twitter import *

t = Twitter(auth=OAuth(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, 
        ACCESS_TOKEN, ACCESS_TOKEN_SECRET))

t.statuses.home_timeline()
query=raw_input("enter the query \n")
data = t.search.tweets(q=query)

for i in range (0,1000):    
    print data['statuses'][i]['text']
    print '\n'

Here, I fetch tweets from all the languages. Is there a way to restrict myself to fetching tweets only in English?

2 Answers

I try this for farsi:

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)

auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth) 

res = api.search('lang','fa')
for i in res:
    print( i.lang)
Related