Tweepy public streams follow filter


Is there any way to filter only tweets created by the user in “stream.filter(follow=)” and not to receive other stuff
i just have no idea how to do it


hi do you find the way to solve the problem?
I am also feel no idea of this question now .


Hello, twt1twt5 and MingyangPan

How about checking in StreamListener class like this:

# users to follow
follow_users_ids = ['271828', '182846']

# override on_status()
class StreamListener(tweepy.StreamListener):
    def on_status(self, status):
        if in follow_users_ids:
# run stream
stream_listener = StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=stream_listener)


hi dear shuuji3,
could you have a look at my code and tell me where it is wrong ?
follow_acc = [‘759251’] #cnn id
track_words = [‘New Zealand flag’]

class listener(StreamListener):

    def on_data(self, data):


##            print data



            tweet = data.split(',"text":"')[1].split('","source')[0]

            screen_name = data.split(',"screen_name":"')[1].split('","location')[0]

            followers_count = data.split(',"followers_count":')[1].split(',"friends_count')[0]


            saveThis = str(time.time())+'::'+ tweet +'::'+ screen_name +'::'+ followers_count

            print saveThis


            saveFile = open('twitDB11.txt','a')





            return True

        except BaseException, e:

            print 'failed ondata,', str(e)



    def on_error(self, status_code):
        if status_code == 420:
            #returning False in on_data disconnects the stream
            return False

        print status

    def on_status(self, status):

        if in follow_acc and track_words in status.text.lower() :

if __name__ == '__main__':

    twitterStream = Stream(auth, listener())
    twitterStream.filter(follow= follow_acc, track = track_words)


Hi, MingyangPan

Tweepy’s on_data() method gives us a bit raw data. So Tweepy provides useful handlers methods such as on_status(), on_event(), etc. In your case, you don’t have to use on_data(), just use on_status() method.

I’d like to write code to do what your code intends like this code:

follow_acc = ['759251'] #cnn id 
track_words = ['New Zealand flag'] # if remove ReTweets, add '-RT' in the word

class Listener(StreamListener):
    def on_status(self, status):
        with open('twitDB11.txt', 'a') as f:
            # status.created_at is datetime object and status.text is the tweet's text
            text = '::'.join([str(status.created_at), status.text,]) + '\n'

if __name__ == '__main__':

    twitterStream = Stream(auth, Listener())
    twitterStream.filter(follow= follow_acc, track = track_words)

By running this code, I got twitDB11.txt which contains:

2015-12-18 17:04:05::RT @CNN: Just In: #StarWars: #TheForceAwakens has record $57 million opening night
2015-12-18 17:04:08::@CNN Overhyped crap!!!::garrybluenose
2015-12-18 17:04:09::RT @CNN: Just In: #StarWars: #TheForceAwakens has record $57 million opening night
2015-12-18 17:04:11::RT @CNN: Just In: #StarWars: #TheForceAwakens has record $57 million opening night
2015-12-18 17:04:14::@CNN Just another point of view on stormtroopers...
2015-12-18 17:04:16::RT @CNN: Just In: #StarWars: #TheForceAwakens has record $57 million opening night
2015-12-18 17:04:16::RT @CNN: .@SenAngusKing: "A mistake" for @POTUS to downplay possible attack


this is the problem i’d like to say that the feedback only give me @cnn but not 'new zealand '. i want to get feedback like @cnn: new zealand…


def on_status(self, status):
        if in follow_acc:

            if track_words in status.text.lower():

                print status.text


                print("No keywords")


            print("No coordinates")

        return True

I use this code but keep getting No coordinates. I dont know where i wrong.