def ensure_stream(self, path): """ Opens stream connection if not already existing. """ if path in self.STREAMS: return # create stream instance stream = TweetStream(self.auth_configuration, ioloop=self.ioloop) # prepare callback function (usage of closures) def tweet_callback(message): """ Publish message """ for client_connection in self.CLIENTS[path]: client_connection.write_message(message) # open stream stream.fetch(path, callback=tweet_callback) # save stream self.STREAMS[path] = stream
def main(): stream = TweetStream(clean=True) stream.fetch(SETTINGS["twitter_url"], callback=tweet_callback) IOLoop.instance().start()