Exemplo n.º 1
0
    def on_error(self, status_code):
        print >> sys.stderr, 'Encountered error with status code:', status_code
        return True # Don't kill the stream

    def on_timeout(self):
        print >> sys.stderr, 'Timeout...'
        return True # Don't kill the stream 

if __name__ == '__main__':

    #con = Connection('localhost')
    #db = con.tweettest
    #col = db.foo

    auth = get_oauth()
    stream = Stream(auth, AbstractedlyListener(), secure=True)
    stream.timeout = None
    # stream.filter(track=["twitter"])
    # stream.filter(languages=['ja'], track=['ja'])
    while True:
        try: 
            stream.sample()
        except Exception:
            time.sleep(20)
            print "sleep 20 sec"
            stream = Stream(auth, AbstractedlyListener(), secure=True)