def testGetCurrentTags(self): import mdb cwd = os.getcwd() parent = os.path.dirname(cwd) cfgs = os.path.join(parent, 'config/twitterCrowded.cfg') p = getConfigParameters(cfgs) # 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: print "Failed to connect to mongo." sys.exit(1) res = cf.getCurrentTags(evCollHandle, 'shitbrick') self.assertEquals(res, ['hellworld', 'fuckhole', 'shitbrick']) # Quick test chucked in results = cf.getQueryBBox(evCollHandle) print results
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))
def testGetCurrentTags(self): import mdb cwd = os.getcwd() parent = os.path.dirname(cwd) cfgs = os.path.join(parent, 'config/twitterCrowded.cfg') p = getConfigParameters(cfgs) # 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: print "Failed to connect to mongo." sys.exit(1) res = cf.getCurrentTags(evCollHandle, 'shitbrick') self.assertEquals(res, ['hellworld','fuckhole', 'shitbrick']) # Quick test chucked in results = cf.getQueryBBox(evCollHandle) print results