def get_chuan_history(self, user_id=''):
        if not user_id:
            logger.error('userid:%s is null'% user_id)
            raise Exception('userid:%s is null'% user_id)

        uv = UserVideo(user = user_id, base = self.__base)
        result = {}
        topic_list = []
        result['tagList'] = topic_list

        obj_all = {}
        topic_list.append(obj_all)
        obj_all['text'] = '全部'
        video_items = []
        obj_all['itemList'] = video_items

        tag_list = {}

        for obj in uv.get_items_obj():
            item = assemble(obj.video_obj)
            video_items.append(item)
            tag_obj = tag_list.setdefault(obj.game_name, {})
            if not (tag_obj.has_key('text') and tag_obj.has_key('itemList')) :
                tag_obj['text'] = obj.game_name
                tag_obj['itemList'] = []

            tag_obj['itemList'].append(item)

        for _,obj in tag_list.iteritems():
            topic_list.append(obj)

        return result
Exemple #2
0
def ub():
    logger.info('rec a ub request')
    data = request.json
    uid = data.get('userid')
    vid = data.get('id')
    if validSqlInject(vid) or validSqlInject(uid):
        return jsonify({'code': 1, 'msg': 'invalid param'})
    if not (uid and vid):
        logger.info('fail|userid or vid is null, return')
        return jsonify({'code': -1, 'msg': 'need userid and vid'})
    if len(uid) > 32 or len(vid) > 32:
        logger.info('fail|userid or vid is invalid,userid:%s,vid:%s return' %
                    (uid, vid))
        return jsonify({'code': -1, 'msg': 'userid and vid invalid.'})
    duration = data.get('duration') or 0

    b = BaseDao()
    try:
        uv = UserVideo(base=b)
        v_dao = Video(base=b)
        uv.add_item(uid, vid, int(time.time()), duration)
        v_dao.add_play_count(vid)
        logger.info('success|ub request serve success')
    except:
        logger.error('fail|exception|ub request serve error|%s' %
                     traceback.format_exc())
    finally:
        b.close()

    return jsonify({'code': 0, 'msg': 'success'})
 def add_history(self, user_id=0, video_id='', duration=0):
     import time
     if not (user_id and video_id):
         logger.error('userid:%s or video_id is null'% user_id)
         raise Exception('userid:%s or video_id is null'% user_id)
     ts = int(time.time())
     uv = UserVideo(user = user_id, base = self.__base)
     uv.add_item(user_id, video_id, ts, duration)
    def get_behavior(self):
        if not self.user:
            logger.warn('need user, return')
            return
        try:
            user_video_dao = UserVideo(self.user, self.base)
            for vid,tag,weight in user_video_dao.get_vid_and_tags():
                yield (self.user, vid, tag, weight)

        except:
            logger.error('fail|exception|get_behavior error|%s' % traceback.format_exc())
        finally:
            pass
Exemple #5
0
 def recommend(self):
     uv = UserVideo(base=self.base)
     ur = UserRecommender(base=self.base)
     for user_id in uv.get_all_users():
         video_logger.info('start rec video of user_id:%s' % user_id)
         items = []
         for k, v in get_rec_list(self.num, user_id):
             items.append(k)
         if len(items):
             rec_list_str = ','.join(items)
             video_logger.info('add user:%s recommend:%s' %
                               (user_id, rec_list_str))
             ur.add_recommend(user_id, rec_list_str)
         video_logger.info('finish rec user_id:%s' % user_id)
 def get_recommend(self):
     uv = UserVideo(self.user, self.base)
     return uv.get_recommend()
 def del_all_video_history(self):
     uv = UserVideo(self.user, self.base)
     uv.del_all_item()
 def del_video_history(self, vid):
     uv = UserVideo(self.user, self.base)
     uv.del_item(vid=vid)
Exemple #9
0
 def get_video_items(self):
     uv = UserVideo(self.user, self.base)
     return assemble_history_content(uv.get_items_obj())