def availableimages(self, camid=None, start=None, end=None): """ /availableimages?camid=X&start=Y&end=Z Get the images within the provided range, only for the specified camid is one is provided. """ if start == None or start == "": start = Utils.timestamp_datetime_to_str(datetime(1970, 1, 1)) if end == None or end == "": end = Utils.timestamp_datetime_to_str(datetime.now()) try: if camid == None or camid == "": imgtups = self.db.get_images_for_range(start, end) else: imgtups = self.db.get_images_for_range_camid(camid, start, end) return {"imgurls": self.package_images(imgtups)} except: return {"imgurls": []}
def get_most_recent_images( self, limit ): ''' Get a list of the most recent images, up to the specified limit. Returns a list of tuples (camid, timestamp). ''' session = self.Session() imgs = [] for row in session.query( Image ).\ order_by( Image.timestamp )[:limit]: imgs.append( (row.camid, Utils.timestamp_datetime_to_str( row.timestamp ) ) ) return imgs
def multiupload( self, camid=0, rotate=0, length=[] ): ''' /multiupload?camid=X&rotate=Y&length=Z1&length=Z2&...&length=Zn Inserts metadata about the uploaded image into the DB and saves the image to disk. Returns a JSON struct containing the camids and timestamps necessary to access the images once they've been post-processed and made available through the web server. ''' content_length = cherrypy.request.headers['Content-Length'] content_type = cherrypy.request.headers['Content-Type'] raw = cherrypy.request.body.read( int( content_length ) ) if self.db.get_desc_for_camid( camid ) == None: return { 'camids' : [], 'timestamps' : [] } if type( length ) != type( [] ): length = [length, ] if content_type == 'image/jpeg': now = datetime.now() delta = timedelta( microseconds=1 ) camids = [] timestamps = [] for img_len in length: img_len = int( img_len ) img = raw[:img_len] raw = raw[img_len:] timestamp = Utils.timestamp_datetime_to_str( now ) self.queue.put( (content_type, camid, timestamp, rotate, img) ) camids.append( camid ) timestamps.append( timestamp ) now += delta return { 'camids' : camids, 'timestamps' : timestamps } return { 'camids' : [], 'timestamps' : [] }
def get_images_for_range_camid( self, camid, start, end ): ''' Get a list of the images between timestamps start and end for the provided camid. List of tuples (camid, timestamp). ''' session = self.Session() start = Utils.timestamp_str_to_datetime( start ) end = Utils.timestamp_str_to_datetime( end ) imgs = [] for row in session.query( Image ).\ filter( Image.camid==camid).\ filter( Image.timestamp > start ).\ filter( Image.timestamp < end ).\ order_by( Image.timestamp ): imgs.append( (row.camid, Utils.timestamp_datetime_to_str( row.timestamp ) ) ) return imgs