Exemple #1
0
def listen(keywords, output):
    config = get_config()
    start_time = time.time() #grabs the system time

    auth = get_auth()

    proxy = os.environ.get('https_proxy', None)
    api = API(auth, proxy=proxy)
    logger.info(
      "Listening for messages with keywords: %s from Kuala Lumpur timezone" % (
          ','.join(keywords)
    ))
    twitterStream = Stream(auth, Listener(api, output)) #initialize Stream object with a time out limit
    twitterStream.api = api
    while True:
        try:
            twitterStream.filter(track=keywords)  #call the filter method to run the Stream Object
        except FirehoseLimitExceeded, e:
            traceback.print_exc()
            logger.info("Firehose Limit Exceeded. Attempting to rebind")
            time.sleep(5)
Exemple #2
0
        locationdb = couch.create(locationdatabase)
    else:
        locationdb = couch[locationdatabase]

    if my_rank == 'vm2':
        #STREAMER
        while (True):
            try:
                twitter_stream = Stream(
                    auth,
                    MyListener(dbs=dbs,
                               args=args,
                               userdb=userdb,
                               locationdb=locationdb))
                api = tweepy.API(auth)
                twitter_stream.api = api

                #This is the bounding box within which we want tweets
                boundingbox = config['Stream']['Location']
                boundingbox = boundingbox.split(',')
                loc1 = float(boundingbox[0])
                loc2 = float(boundingbox[1])
                loc3 = float(boundingbox[2])
                loc4 = float(boundingbox[3])
                #Set up the stream
                twitter_stream.filter(locations=[loc1, loc2, loc3, loc4])
            except Exception as e:
                print(e)
                time.sleep(15)
                pass