Esempio n. 1
0
 def testFileComparison(self):
     ''' Check whether we can successfully match files by byte comparison.'''
     
     parent = os.getcwd()
     localDir      = os.path.join(parent, 'comparisons')
     imageFileName = os.path.join(parent, 'candidate/candidateImage.jpg')
     
     same = tflWorker.alreadyExists(localDir, imageFileName)
     self.assertTrue(same)
Esempio n. 2
0
def get_tflCams():
    ''' Gets the tfl cameras that were within a certain location '''

    # Where to stage and store the full res and thumbnail
    imageDir = os.path.join(p.webStaticRoute, 'images')

    # Parse out the geo parameters
    lat, lon, radius = tflWorker.checkGeos(request.query.lat, request.query.lon, request.query.radius)
    
    if not lat or not lon or not radius:
        res = {'code':500, 'reason': 'lat/lon/radius not within bounds.'}
        return json.dumps(res)
    
    # Get the documents that fall within the search radius
    cameras = tflWorker.getCamsByGeo(p, lat, lon, radius)
    
    mediaOut = []
    
    if cameras:
        for camera in cameras:

            # Get the iamge dt for writing unique image files
            if camera['captured'] != None:
                dt = camera['captured'].strftime('%y%m%d%H%M%S') 
            else:
                dt = camera['published'].strftime('%y%m%d%H%M%S')
            
            # Build output json
            camMedia, reason = tflWorker.formatOutput(p, camera)
            if not camMedia:
                return json.dumps({'code':500, 'reason': "Failed to format the camera metadata."})
            
            # Create a local version of the TFL image for thumbnail and scaled up images
            localFile, reason = tflWorker.getFullRes(p, imageDir, camMedia['standard_resolution'], dt)

            # Do a byte-based comparison to see whether this image already exists in the originals/ directory
            dupe = tflWorker.alreadyExists(imageDir, localFile)
            
            # Remove the one we've just pulled down
            if dupe:
                out, reason = tflWorker.removeFullRes(localFile)
                continue
            
            if not localFile:
                return json.dumps({'code':500, 'reason': "Failed to get the full resolution image."})
            largeFile, reason = tflWorker.createLargerImage(imageDir, localFile, scale=1.2)
            
            # Build a thumbnail
            imageThumb, reason = tflWorker.createThumbnail(imageDir, localFile, size=100)
            if not imageThumb:
                return json.dumps({'code':500, 'reason': "Failed to create the thumbnail."})
            
            #out, reason = tflWorker.removeFullRes(localFile)
            camMedia['thumbnail']           = tflWorker.assignLocalCopies(p, imageThumb)
            camMedia['standard_resolution'] = tflWorker.assignLocalCopies(p, largeFile)
            camMedia['low_resolution']      = tflWorker.assignLocalCopies(p, largeFile)

            mediaOut.append(camMedia)
            
    else:
        mediaOut = []
    
    return json.dumps(mediaOut)