def testWhichTag(self): currentTags = ['xfactor'] f = open(os.path.join(os.getcwd(), 'sampleTweet.json'), 'r') tweet = json.loads(f.read()) tags = cf.whichTags(currentTags, tweet) self.assertEquals(currentTags, tags)
def main(p): # The mongo bits try: c, dbh = mdb.getHandle(host=p.dbHost, port=p.dbPort, db=p.db, user=p.dbUser, password=p.dbPassword) evCollHandle = dbh[p.eventsCollection] except: logging.critical('Failed to connect and authenticate', exc_info=True) sys.exit() # Get the current tags tags = cf.getCurrentTags(evCollHandle) # Get the current bounding boxes queryBBoxes = cf.getQueryBBox(evCollHandle) x = 1 while x == 1: # Here's the redis queue for managing the tweets as they come in try: q = RedisQueue(p.redisName, host=p.redisHost, password=p.redisPassword, port=p.redisPort, db=0) except: logging.error('Failed to connect to REDIS db.', exc_info=True) sys.exit() # This call is blocking, so expect it to hang on this point tweetStr = q.get() tweet = json.loads(tweetStr) # Work out which object/event this tweet is associated with if tags: tweetTags = cf.whichTags(tags, tweet) for tweetTag in tweetTags: success = dispatchTweet(p, tweet, tweetTag) logging.debug("Tag-based message dispatched: %s" % (success)) if queryBBoxes: tweetGeos = cf.matchesCurrentGeos(queryBBoxes, tweet) for tweetGeo in tweetGeos: success = dispatchTweet(p, tweet, tweetGeo) logging.debug("Geo-based message dispatched: %s" % (success))
def main(p): # The mongo bits try: c, dbh = mdb.getHandle(host=p.dbHost, port=p.dbPort, db=p.db, user=p.dbUser, password=p.dbPassword) evCollHandle = dbh[p.eventsCollection] except: logging.critical('Failed to connect and authenticate', exc_info=True) sys.exit() # Get the current tags tags = cf.getCurrentTags(evCollHandle) # Get the current bounding boxes queryBBoxes = cf.getQueryBBox(evCollHandle) x = 1 while x == 1: # Here's the redis queue for managing the tweets as they come in try: q = RedisQueue(p.redisName, host=p.redisHost, password=p.redisPassword, port=p.redisPort, db=0) except: logging.error('Failed to connect to REDIS db.', exc_info=True) sys.exit() # This call is blocking, so expect it to hang on this point tweetStr = q.get() tweet = json.loads(tweetStr) # Work out which object/event this tweet is associated with if tags: tweetTags = cf.whichTags(tags, tweet) for tweetTag in tweetTags: success = dispatchTweet(p, tweet, tweetTag) logging.debug("Tag-based message dispatched: %s" %(success)) if queryBBoxes: tweetGeos = cf.matchesCurrentGeos(queryBBoxes, tweet) for tweetGeo in tweetGeos: success = dispatchTweet(p, tweet, tweetGeo) logging.debug("Geo-based message dispatched: %s" %(success))