def get_user_profile(): res = {'code': 1000, 'msg': '成功'} data = request.json data = data.get('data') if data else None if not data: return handle_param_error() user_id = data.get("userid") or 0 if not user_id: return handle_param_error() service = ProfileService() try: result = service.get_user_profile(user_id) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|user profile request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_master_list(): res = {'code': 1000, 'msg': '成功'} data = request.json command = data.get("cmd") or '' data = data.get('data') if not data: return handle_param_error() user_id = data.get("userid") or 0 page_num = data.get("page_num") or 1 if not command or not page_num: return handle_param_error() service = ProfileService() try: result = service.get_master_list(page_num) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|master list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def update_user_profile(): res = {'code': 1000, 'msg': '成功'} data = request.json data = data.get('data') if data else None if not data: return handle_param_error() user_id = data.get("userid") or 0 signature = data.get("signature") or '' nickname = data.get("nickname") or '' user_icon = data.get("user_icon") or '' user_pics = data.get("user_pics") or [] if not user_id or not nickname or not user_icon: return handle_param_error() service = ProfileService() try: result = service.update_user_profile_diy(user_id=user_id, signature=signature, nickname=nickname, user_icon=user_icon, user_pics=user_pics) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|user profile request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def is_watch(): res = {'code': 1000, 'msg': '成功'} data = request.json data = data.get('data') if not data: return handle_param_error() user_id = data.get("userid") or 0 req_user_id = data.get("req_user_id") or 0 if not user_id or not req_user_id: return handle_param_error() service = ProfileService() try: result = service.user_watch_relation(user_id, req_user_id) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|is watch request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def add_watch(): res = {'code' : 1000, 'msg' : '成功'} data = request.json command = data.get("cmd") or '' data = data.get('data') if not data: return handle_param_error() user_id = data.get("userid") or 0 req_user_id = data.get("req_user_id") or 0 status = data.get("status") or 0 if not command or not user_id: return handle_param_error() service = ProfileService() try: result = service.watch(user_id, req_user_id, status) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|user watch request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_video_by_user(self, user_id=0, req_user_id=0, begin_sec=0, begin_usec=0, batch_num=30): data = {} data['videos'] = [] data['total'] = 0 data['user_info'] = [] data['is_watch'] = False self.__base = self.__base or BaseDao() try: req_user_info = { 'req_user_id': req_user_id, 'begin_sec': begin_sec, 'begin_usec': begin_usec } res_obj = self.get_video_by_users(user_id=user_id, req_user_ids=[req_user_info], batch_num=batch_num) data['videos'] = res_obj.get('videos') data['total'] = res_obj.get('total') data['user_info'] = res_obj.get('user_info') ps = ProfileService(base=self.__base) is_watch = ps.is_watch(user_id, req_user_id) data['is_watch'] = is_watch except: logger.error(traceback.format_exc()) finally: return data
def get_qq_code(): res = {'code':1000,'msg':'success'} codee = request.args.get("code") if not codee: logger.info('fail|code arg not found, return') return handle_param_error() try: logger.info('get qq codee:%s'%codee) loginS = QQLoginService(appid=QQ_APP_ID, secret=QQ_APP_SECRET) token,obj,expires = loginS.get_user_info_by_code(codee) if not (token and obj): logger.info('fail|get_user_info_by_code fail,code:%s, return'%codee) res['code'] = -1 res['msg'] = 'login fail' return jsonify(res) #chuan_id = get_chuan_id_by_openid(openid) ps = ProfileService() userid = ps.insert_user_profile(obj) #nickname = urllib.quote(obj['nickname']) #usericon = urllib.quote(obj['usericon']) #expires = urllib.quote(expires) logger.info('token:%s, obj:%s, expires:%s, userid:%s'%(token,obj,expires,userid)) return redirect("http://nbstorage.sparta.html5.qq.com/qq/code/result?token=%s&userid=%s"%(token,userid), code=302) except: res = handle_failure() logger.error('fail|exception|ub request serve error|%s' % traceback.format_exc()) return res
def get_watch(): logger.info('rec a user watch request') res = {'code': 1000, 'msg': '成功'} data = request.json command = data.get("cmd") or '' data = data.get('data') if not check_param(data): return handle_param_error() logger.info('request data => {0}'.format(data)) user_id = data.get("userid") or 0 req_user_id = data.get("req_user_id") or 0 page_num = data.get("page_num") or 0 if not command or not user_id or not check_param(data): return handle_param_error() service = ProfileService() try: result = service.get_watch(req_user_id, page_num) res = handle_success(result, 1000, '成功') logger.info('success|user watch request serve success') except: res = handle_failure() logger.error('fail|exception|user watch request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def valid_wx_access_token(): res = {'code':1000,'msg':'success','data':{}} token = request.args.get("token") userid = request.args.get("userid") if not (token and userid): return handle_param_error() logger.info('get weixin token:%s, userid:%s'%(token,userid)) ps = ProfileService() openid = ps.get_uid_by_userid(userid) try: token_serv = WeiXinLoginService(appid=WX_APP_ID, secret=WX_APP_SECRET) token,session,obj = token_serv.get_user_info_by_token(openid=openid, access_token=token) if not (token and session and obj): logger.info('fail|valid_wx_access_token fail,token:%s,session:%s, obj:%s.'%(token,session,obj)) return handle_failure() result = {} result['token'] = token result['session'] = session #data['userinfo'] = obj ps.update_user_profile(obj) res = handle_success(result, 1000, '成功') logger.info('valid_wx_access_token response:%s'%result) except: res = handle_failure() logger.error('fail|exception|ub request serve error|%s' % traceback.format_exc()) finally: ps.close() return res
def get_weixin_code(): res = {'code':1000,'msg':'success'} codee = request.args.get("code") if not codee: logger.info('fail|code arg not found, return') return handle_param_error() try: logger.info('get weixin codee:%s'%codee) loginS = WeiXinLoginService(appid=WX_APP_ID, secret=WX_APP_SECRET) token,obj = loginS.get_user_info_by_code(codee) obj['uid_type'] = 2 if not (token and obj): logger.info('fail|get_user_info_by_code fail,code:%s, return'%codee) return handle_failure() #chuan_id = get_chuan_id_by_openid(openid) ps = ProfileService() userid = ps.insert_user_profile(obj) if not userid: obj = ps.get_user_profile_by_uid(obj['openid']) if obj: userid = obj['userid'] if not userid: logger.warn('fail|get_user_info_by_code fail,userid is null,code:%s, return'%codee) return handle_failure() #nickname = urllib.quote(obj['nickname']) #usericon = urllib.quote(obj['usericon']) #expires = urllib.quote(expires) result = {} result['token'] = token result['userid'] = userid res = handle_success(result, 1000, '成功') logger.info('get_weixin_code response:%s'%result) #return redirect("http://nbstorage.sparta.html5.qq.com/qq/code/result?token=%s&userid=%s"%(token,userid), code=302) except: res = handle_failure() logger.error('fail|exception|ub request serve error|%s' % traceback.format_exc()) return res
def get_user_see_history(self, user_id=0, req_user_id=0, page_num=0): self.__base = self.__base or BaseDao() video = Video(self.__base) (total, rows) = video.get_user_see_history(page_num, 30, req_user_id) arr = [] for row in rows: v = row.toDict() arr.append(v) service = ProfileService() is_watch = service.is_watch(user_id, req_user_id) service.close() data = {} data['videos'] = arr data['total'] = total data['is_watch'] = is_watch return data