Ejemplo n.º 1
0
    async def post(self):
        r_dict = {'code': 0}
        try:
            pageNum = int(self.get_i_argument('pageNum', 1))
            size = int(self.get_i_argument('size', 10))
            skip = (pageNum - 1) * size if (pageNum - 1) * size > 0 else 0
            filter_dict = {'db_mark': {'$ne': ''}, 'release_time': {'$ne': ''}}

            match = MatchStage(filter_dict)
            skip = SkipStage(skip)
            sort = SortStage([('release_time', DESC)])
            limit = LimitStage(int(size))
            count = await Tvs.count({
                'db_mark': {
                    '$ne': ''
                },
                'release_time': {
                    '$ne': ''
                }
            })
            tvs = await Tvs.aggregate([match, sort, skip, limit]).to_list(None)
            new_tvs = []
            for tv in tvs:
                new_tvs.append({
                    'id':
                    str(tv.id),
                    'name':
                    tv.name,
                    'pic_url':
                    tv.pic_url,
                    'db_mark':
                    tv.db_mark,
                    'actor':
                    tv.actor,
                    'source_nums':
                    len(tv.download),
                    'release_time':
                    tv.release_time.strftime('%Y-%m-%d'),
                    'label':
                    api_utils.get_show_source_label(tv),
                    'recommend_info':
                    '这部神剧值得一看。',
                    'set_num':
                    tv.set_num if tv.set_num else '',
                    's_type':
                    'tv'
                })
            r_dict['tvs'] = new_tvs
            r_dict['count'] = count
            r_dict['code'] = 1000
        except Exception:
            logger.error(traceback.format_exc())
        print('latest')
        print(r_dict)
        return r_dict
Ejemplo n.º 2
0
    async def post(self):
        r_dict = {'code': 0}
        try:
            search_name = self.get_i_argument('search_name', None)
            member_cid = self.get_i_argument('member_cid', None)
            s_type = self.get_i_argument('s_type', None)
            if not member_cid:
                r_dict['code'] = 1001  # member_cid为空
                return r_dict
            if not search_name:
                r_dict['code'] = 1002  # 检索名称为空
                return r_dict
            if not s_type:
                r_dict['code'] = 1003  # 资源类型为空
                return r_dict
            pageNum = int(self.get_i_argument('pageNum', 1))
            size = int(self.get_i_argument('size', 10))
            skip = (pageNum - 1) * size if (pageNum - 1) * size > 0 else 0
            filter_dict = {
                'db_mark': {
                    '$ne': ''
                },
                'release_time': {
                    '$ne': ''
                },
                'status':
                1,
                '$or': [
                    {
                        'name': {
                            '$regex': search_name
                        }
                    },
                    {
                        'actor': {
                            '$regex': search_name
                        }
                    },
                    {
                        'director': {
                            '$regex': search_name
                        }
                    },
                    {
                        'label': {
                            '$regex': search_name
                        }
                    },
                ]
            }
            match = MatchStage(filter_dict)
            skip = SkipStage(skip)
            sort = SortStage([('db_mark', DESC)])
            limit = LimitStage(int(size))
            if s_type == 'film':
                films = await Films.aggregate([match, sort, skip,
                                               limit]).to_list(None)
                new_films = []
                for film in films:
                    new_films.append({
                        'id':
                        str(film.id),
                        'name':
                        film.name,
                        'pic_url':
                        film.pic_url,
                        'stage_photo':
                        [k['img_url'] for k in film.stage_photo][0:4]
                        if film.stage_photo else [],
                        's_type':
                        'film',
                        'label':
                        api_utils.get_show_source_label(film),
                        'articulation':
                        api_utils.get_show_source_articulation(film),
                        'db_mark':
                        film.db_mark,
                        'actor':
                        film.actor,
                        'source_nums':
                        len(film.download),
                        'release_time':
                        film.release_time.strftime('%Y-%m-%d'),
                        'recommend_info':
                        film.recommend_info
                        if film.recommend_info else '这部神片值得一看。'
                    })
                r_dict['sources'] = new_films
            elif s_type == 'tv':
                tvs = await Tvs.aggregate([match, sort, skip,
                                           limit]).to_list(None)
                new_tvs = []
                for tv in tvs:
                    new_tvs.append({
                        'id':
                        str(tv.id),
                        'name':
                        tv.name,
                        'pic_url':
                        tv.pic_url,
                        'stage_photo': [k['img_url'] for k in tv.stage_photo
                                        ][0:4] if tv.stage_photo else [],
                        's_type':
                        'tv',
                        'label':
                        api_utils.get_show_source_label(tv),
                        'articulation':
                        api_utils.get_show_source_articulation(tv),
                        'db_mark':
                        tv.db_mark,
                        'actor':
                        tv.actor,
                        'source_nums':
                        len(tv.download),
                        'release_time':
                        tv.release_time.strftime('%Y-%m-%d'),
                        'recommend_info':
                        '这部神剧值得一看。'
                    })
                r_dict['sources'] = new_tvs

            r_dict['code'] = 1000
        except Exception:
            logger.error(traceback.format_exc())
        return r_dict
Ejemplo n.º 3
0
 async def post(self):
     r_dict = {'code': 0}
     try:
         member_cid = self.get_i_argument('member_cid', None)
         pageNum = int(self.get_i_argument('pageNum', 1))
         size = int(self.get_i_argument('size', 10))
         skip = (pageNum - 1) * size if (pageNum - 1) * size > 0 else 0
         if member_cid:
             member = await find_app_member_by_cid(member_cid)
             if not member:
                 r_dict['code'] = 1002  # 没有匹配到用户
             else:
                 if not member.is_register:
                     r_dict['code'] = 1003  # 用户未登陆不展示收藏列表
                     return r_dict
                 filter_dict = {
                     'member_cid': member_cid,
                     'status': COLLECTION_STATUS_ACTIVE
                 }
                 match = MatchStage(filter_dict)
                 skip = SkipStage(skip)
                 sort = SortStage([('updated_dt', DESC)])
                 limit = LimitStage(int(size))
                 my_collect_list = await MyCollection.aggregate(
                     [match, sort, skip, limit]).to_list(None)
                 show_my_list = []
                 for my_collect in my_collect_list:
                     if my_collect.s_type == 'film':
                         film = await Films.find_one(
                             {'_id': ObjectId(my_collect.source_id)})
                         show_my_list.append({
                             'id':
                             str(film.id),
                             'name':
                             film.name,
                             'pic_url':
                             film.pic_url,
                             's_type':
                             'film',
                             'db_mark':
                             film.db_mark,
                             'actor':
                             film.actor,
                             'source_nums':
                             len(film.download),
                             'release_time':
                             film.release_time.strftime('%Y-%m-%d'),
                             'recommend_info':
                             film.recommend_info
                             if film.recommend_info else '这部神片值得一看。',
                             'label':
                             api_utils.get_show_source_label(film)
                         })
                     elif my_collect.s_type == 'tv':
                         tv = await Tvs.find_one(
                             {'_id': ObjectId(my_collect.source_id)})
                         show_my_list.append({
                             'id':
                             str(tv.id),
                             'name':
                             tv.name,
                             'pic_url':
                             tv.pic_url,
                             's_type':
                             'tv',
                             'db_mark':
                             tv.db_mark,
                             'actor':
                             tv.actor,
                             'source_nums':
                             len(tv.download),
                             'release_time':
                             tv.release_time.strftime('%Y-%m-%d'),
                             'recommend_info':
                             tv.recommend_info
                             if tv.recommend_info else '这部神剧值得一看。',
                             'label':
                             api_utils.get_show_source_label(tv),
                             'set_num':
                             tv.set_num if tv.set_num else ''
                         })
                 r_dict['my_collect_list'] = show_my_list
                 r_dict['code'] = 1000
         else:
             r_dict['code'] = 1001  # member_cid为空
     except Exception:
         logger.error(traceback.format_exc())
     print(r_dict)
     return r_dict
Ejemplo n.º 4
0
 async def post(self):
     r_dict = {'code': 0}
     try:
         pageNum = int(self.get_i_argument('pageNum', 1))
         member_cid = self.get_i_argument('member_cid', None)
         if not member_cid:
             r_dict['code'] = 1001
             return r_dict
         if pageNum == 1:
             exclude_list = []
             RedisCache.delete('%s_film_recommend' % member_cid)
         else:
             exclude_list = RedisCache.smembers('%s_film_recommend' %
                                                member_cid)
             if isinstance(exclude_list, (list, set)):
                 exclude_list = list(exclude_list)
         size = int(self.get_i_argument('size', 10))
         filter_dict = {
             'db_mark': {
                 '$ne': ''
             },
             'release_time': {
                 '$ne': ''
             },
             'oid': {
                 '$nin': exclude_list
             }
         }
         match = MatchStage(filter_dict)
         sample = SampleStage(size)
         films = await Films.aggregate([match, sample]).to_list(None)
         new_films = []
         id_list = []
         for film in films:
             id_list.append(str(film.id))
             new_films.append({
                 'id':
                 str(film.id),
                 'name':
                 film.name,
                 'pic_url':
                 film.pic_url,
                 'db_mark':
                 film.db_mark,
                 'actor':
                 film.actor,
                 'label':
                 api_utils.get_show_source_label(film),
                 'source_nums':
                 len(film.download),
                 'release_time':
                 film.release_time.strftime('%Y-%m-%d'),
                 'articulation':
                 api_utils.get_show_source_articulation(film),
                 'recommend_info':
                 film.recommend_info
                 if film.recommend_info else '这部神片值得一看。',
                 's_type':
                 'film',
                 'stage_photo': [k['img_url'] for k in film.stage_photo
                                 ][0:4] if film.stage_photo else []
             })
         r_dict['films'] = new_films
         if id_list:
             RedisCache.sadd('%s_film_recommend' % member_cid, id_list)
         r_dict['code'] = 1000
         print('recommend')
         print(r_dict)
     except Exception:
         logger.error(traceback.format_exc())
     return r_dict
Ejemplo n.º 5
0
    async def post(self):
        r_dict = {'code': 0}
        try:

            pageNum = int(self.get_i_argument('pageNum', 1))
            size = int(self.get_i_argument('size', 10))
            search_type = self.get_i_argument('search_type', 'all')
            skip = (pageNum - 1) * size if (pageNum - 1) * size > 0 else 0
            filter_dict = {'db_mark': {'$ne': ''}, 'release_time': {'$ne': ''}}
            dif_time = 0
            if search_type == 'week':
                dif_time = 7
            elif search_type == 'month':
                dif_time = 30
            elif search_type == 'year':
                dif_time = 365
            if dif_time:
                show_time = datetime.datetime.now().replace(
                    hour=0, minute=0, second=0,
                    microsecond=0) - datetime.timedelta(days=dif_time)
                filter_dict = {
                    'db_mark': {
                        '$ne': ''
                    },
                    'release_time': {
                        '$ne': '',
                        '$gte': show_time
                    }
                }

            match = MatchStage(filter_dict)
            skip = SkipStage(skip)
            sort = SortStage([('db_mark', DESC)])
            limit = LimitStage(int(size))
            count = await Films.count({
                'db_mark': {
                    '$ne': ''
                },
                'release_time': {
                    '$ne': ''
                }
            })
            films = await Films.aggregate([match, sort, skip,
                                           limit]).to_list(None)
            new_films = []
            for film in films:
                # if len(film.label) > 0:
                #     label = film.label[0:3]
                # else:
                #     label = []
                new_films.append({
                    'id':
                    str(film.id),
                    'name':
                    film.name,
                    'pic_url':
                    film.pic_url,
                    'db_mark':
                    film.db_mark,
                    'actor':
                    film.actor,
                    'source_nums':
                    len(film.download),
                    'release_time':
                    film.release_time.strftime('%Y-%m-%d'),
                    # 'recommend_info': '这部神片值得一看。',
                    'recommend_info':
                    film.recommend_info
                    if film.recommend_info else '这部神片值得一看。',
                    # 'label': label
                    'label':
                    api_utils.get_show_source_label(film),
                    's_type':
                    'film'
                })
            r_dict['films'] = new_films
            r_dict['count'] = count
            r_dict['code'] = 1000
        except Exception:
            logger.error(traceback.format_exc())
        print('score')
        print(r_dict)
        return r_dict
Ejemplo n.º 6
0
    async def post(self):
        r_dict = {'code': 0}
        try:
            pageNum = int(self.get_i_argument('pageNum', 1))
            size = int(self.get_i_argument('size', 10))
            skip = (pageNum - 1) * size if (pageNum - 1) * size > 0 else 0
            filter_dict = {'db_mark': {'$ne': ''}, 'release_time': {'$ne': ''}}

            match = MatchStage(filter_dict)
            skip = SkipStage(skip)
            sort = SortStage([('release_time', DESC)])
            limit = LimitStage(int(size))
            count = await Films.count({
                'db_mark': {
                    '$ne': ''
                },
                'release_time': {
                    '$ne': ''
                }
            })
            films = await Films.aggregate([match, sort, skip,
                                           limit]).to_list(None)
            new_films = []
            for film in films:
                # if len(film.label) > 0:
                #     label = film.label[0:3]
                # else:
                #     label = []
                new_films.append({
                    'id':
                    str(film.id),
                    'name':
                    film.name,
                    'pic_url':
                    film.pic_url,
                    'db_mark':
                    film.db_mark,
                    'actor':
                    film.actor,
                    'source_nums':
                    len(film.download),
                    'release_time':
                    film.release_time.strftime('%Y-%m-%d'),
                    # 'recommend_info': '这部神片值得一看。',
                    'recommend_info':
                    film.recommend_info
                    if film.recommend_info else '这部神片值得一看。',
                    # 'label': label
                    'label':
                    api_utils.get_show_source_label(film),
                    's_type':
                    'film'
                })
            r_dict['films'] = new_films
            r_dict['count'] = count
            r_dict['code'] = 1000
        except Exception:
            logger.error(traceback.format_exc())
        print('latest')
        print(r_dict)
        return r_dict