コード例 #1
0
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))
コード例 #2
0
 def testMatchesCurrentGeos(self):
     
     f = open(os.path.join(os.getcwd(), 'sampleTweet.json'), 'r')
     tweet = json.loads(f.read())
     [-0.13546585999999999, 51.510528880000003]
     queryBBoxes = {'hits':    {'s': 51.504755706271219,
                                'e': -0.10658170627121719,
                                'w': -0.15086429372878282,
                                'n': 51.549038293728778},
                    
                    'miss':    {'s': 51.544755706271219,
                                'e': -0.14658170627121719,
                                'w': -0.17086429372878282,
                                'n': 51.589038293728778}}
     
     bboxIds = cf.matchesCurrentGeos(queryBBoxes, tweet)
     self.assertEquals(bboxIds, ['hits'])
コード例 #3
0
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))
コード例 #4
0
    def testMatchesCurrentGeos(self):

        f = open(os.path.join(os.getcwd(), 'sampleTweet.json'), 'r')
        tweet = json.loads(f.read())
        [-0.13546585999999999, 51.510528880000003]
        queryBBoxes = {
            'hits': {
                's': 51.504755706271219,
                'e': -0.10658170627121719,
                'w': -0.15086429372878282,
                'n': 51.549038293728778
            },
            'miss': {
                's': 51.544755706271219,
                'e': -0.14658170627121719,
                'w': -0.17086429372878282,
                'n': 51.589038293728778
            }
        }

        bboxIds = cf.matchesCurrentGeos(queryBBoxes, tweet)
        self.assertEquals(bboxIds, ['hits'])