简体   繁体   中英

Tweepy stream acting really slow

I'm trying to stream tweets from twitter using Tweepy for a particular hashtag. The problem that I'm facing is that fetching 500 tweets is taking almost around 10-15 minutes. I don't think it is supposed to be that slow? Am I missing anything? Has it got to do with any API rate limits? My tweepy listener looks like this:

class MyListener(StreamListener): """Custom StreamListener for streaming data."""

def __init__(self, lim):
    self.count = 0
    self.limit = lim

def on_data(self, data):
    global tweets
    if self.count < self.limit:
        try:
            self.count += 1
            tweets.append(data)
            return True
        except BaseException, e:
            print 'failed ondata,', str(e)
            time.sleep(5)
            pass
    else:
        return False

def on_error(self, status):
    print(status)
    return True

You are trying to fetch live tweets. It means the rate of your collecting tweets is the rate in which people post tweets with that hashtag. You can try your code with a popular or trending hashtag and you will get outputs faster.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM