Esempio n. 1
0
    def all_videos(self, serialize=False):
        try:
            temp_session = Scope_Session()
            start = time.time()
            videos = temp_session.query(Video).filter(
                Video.status != -1).order_by(
                    Video.upload_time.desc()).offset(40).limit(10)
            print videos
            print("查询所有video用时: %.2fs" % (time.time() - start))

            new_start = time.time()
            count = temp_session.query(Video).filter(
                Video.status != -1).count()
            print count
            print("查询总共有多少video用时: %.2fs" % (time.time() - new_start))

            new_start = time.time()
            count = temp_session.query(func.count(Video.status != -1))
            print count
            print("新方式查询总共有多少video用时: %.2fs" % (time.time() - new_start))

            clean_videos = [Video.get_new_instance(vi) for vi in videos]
            Scope_Session.remove()
            if serialize:
                return [vi.mini_serialize() for vi in clean_videos]
            else:
                return clean_videos
        except (Exception) as e:
            print "抓到exception"
            print "all_videos 操作失败"
            print e.message
            return []
Esempio n. 2
0
    def videos_at_page(self, page=1, key="", serialize=False):
        try:
            offset = (page - 1) * per_page
            temp_session = Scope_Session()
            # count = temp_session.query(func.count(Video.status != -1))
            count = temp_session.query(Video).filter(
                Video.status != -1, Video.name.like('%' + key + '%')).count()
            page_count = int(math.ceil(count / float(per_page)))
            print page_count
            if page_count == 0:
                page_count = 1

            page_indexs = [(i + 1) for i in range(page_count)]
            current_page = page

            videos = temp_session.query(Video).filter(
                Video.status != -1, Video.name.like('%' + key + '%')).order_by(
                    Video.upload_time.desc()).offset(offset).limit(per_page)
            clean_videos = [Video.get_new_instance(vi) for vi in videos]
            Scope_Session.remove()
            if serialize:
                return [vi.mini_serialize()
                        for vi in clean_videos], page_indexs, current_page
            else:
                return clean_videos, page_indexs, current_page
        except (Exception) as e:
            print "抓到exception"
            print "all_videos 操作失败"
            print e.message
            return [], [], 1
Esempio n. 3
0
 def get_all_fetching_caption_videos(self, serialize=False):
     try:
         temp_session = Scope_Session()
         videos = temp_session.query(Video).filter(Video.status == 7).all()
         clean_videos = [Video.get_new_instance(vi) for vi in videos]
         Scope_Session.remove()
         if serialize:
             return [vi.serialize() for vi in clean_videos]
         else:
             return clean_videos
     except (Exception) as e:
         print "抓到exception"
         print "get_all_fetching_caption_videos 操作失败"
         print e.message
Esempio n. 4
0
 def get_video_by_name(self, name, serialize=False):
     try:
         temp_session = Scope_Session()
         videos = temp_session.query(Video).filter(
             Video.name.like('%' + name + '%')).limit(1)
         clean_videos = [Video.get_new_instance(vi) for vi in videos]
         Scope_Session.remove()
         if serialize:
             return [vi.serialize() for vi in clean_videos]
         else:
             return clean_videos
     except (Exception) as e:
         print "抓到exception"
         print e.message
         print "get_video_by_name 操作失败"