2

I made a python script which uses tweepy streaming module to stream mentions to a twitter account and carry some functions based on the status text.

I wanted it to stream until a mention is made, next stop streaming, carry some functions based on the status text and again start streaming.

This is my code:

class StdOutListener(tweepy.StreamListener):

    def on_data(self, data):
        tweet = json.loads(data.strip())
        global d
        d=tweet
        return False #stops streaming after a tweet is fed to it

    def on_error(self, status_code):
        print(status_code)
        time.sleep(120)
        return F # To continue listening

    def on_timeout(self)
        time.sleep(120)
        return True # To continue listening
while True:
    d={}
    listener = StdOutListener()
    stream = tweepy.Stream(twitter_auth(tokens), listener)
    stream.filter(track=['@xxx'])
    stream.disconnect()
    doSomething(d)

But it only works for one loop and later shows 420(Exceeding Rate Limit) errors,even though I just take in a single tweet (per stream, if I'm not wrong).

Can anyone please explain where I'm doing it wrong? And also when should we use async mode in tweepy stream listener?

Novice
  • 73
  • 5
  • anything you are doing is wrong, it's only that twitter api - tweepy is based on that - has limitation on download https://developer.twitter.com/en/docs/basics/rate-limiting – Lupanoide Nov 07 '17 at 15:45

0 Answers0