Beispiel #1
0
    def get(self):
        
        from models import VideoData, VideoViewsData
        
        """
        Selects the videos from the database that are due a check. This is based on the amount of time since they were last checked and on their alert level.
        """
        
        # find the time now
        now = datetime.datetime.now()

        queryModel = VideoData.all()
        count = 0
        
        for video in queryModel:
            
            # get all the views info for that video
            video_views_data = video.views.order("-dateTime")
            
            # get the last one
            latest_views_data = video_views_data.get()
            
            #compare the times
            timeElapsed = now - latest_views_data.dateTime
            
            # if the amount of time passed since last check exceeds the alertLevel for this video
            if (timeElapsed > ALERT_LEVELS[video.alertLevel]): 
                video.checkMeFlag = True
                count += 1
            else:
                video.checkMeFlag = False
            
            video.put()
        
        logging.info('Selected %i videos for checking', count)