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 get_all_game(): logger.info('rec a game list 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 if not command or not check_param(data): return handle_param_error() service = TagService() try: result = service.get_all_content() res = handle_success(result, 1000, '成功') logger.info('success|game list request serve success') except: res = handle_failure() logger.error('fail|exception|game list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_content_list(): logger.info('rec a game video list request') res = {'code': 1000, 'msg': '成功'} data = request.json command = data.get("cmd") or '' logger.info('request data => {0}'.format(data)) data = data.get('data') if not check_param(data): return handle_param_error() user_id = data.get("userid") or 0 page_num = data.get("page_num") or 1 type_class = data.get("type") or 'all' type_id = data.get("type_id") or 'all' tag = data.get("tag") or 'all' if not command or not page_num or not check_param(data): return handle_param_error() service = VideoService() try: result = service.get_class_video(page_num, type_class, type_id, tag) res = handle_success(result, 1000, '成功') logger.info('success|game video list request serve success') except: res = handle_failure() logger.error('fail|exception|game video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_video_url(): 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 vid = data.get("vid") or '' game_id = data.get("game_id") or 0 if not vid: return handle_param_error() service = VideoService() try: result = service.get_url_by_vid(vid=vid,game_id=game_id) if not result['url']: return handle_param_error() res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|url query request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_video_url(): logger.info('rec a url query request') res = {'code': 1000, 'msg': '成功'} data = request.json 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 vid = data.get("vid") or '' if not vid: return handle_param_error() service = VideoService() try: result = service.get_url_by_vid(vid=vid) if not result['url']: return handle_param_error() res = handle_success(result, 1000, '成功') logger.info('success|url query request serve success') except: res = handle_failure() logger.error('fail|exception|url query 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 chuan_video_query(): res = {'code': 1000, 'msg': '成功'} data = request.json data = data.get('data') if not check_param(data): return handle_param_error() user_id = data.get("userid") or 0 if not user_id: return handle_param_error() service = HistoryService() try: result = service.get_chuan_history(user_id=user_id) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error( 'fail|exception|chuan history query list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
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 get_tags(): 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 type_id = data.get("type_id") or 'all' if not type_id: return handle_param_error() service = TagService() try: result = service.get_tag_by_content(type_id) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|tag list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def add_work_dancer(): 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 work_id = data.get("work_id") or 0 duration = data.get("duration") or 0 score = data.get("score") or 0 #ts = int(time.time()) if not user_id or not work_id or not score: return handle_param_error() service = DanceService() try: result = service.add_work_dancer(user_id=user_id, work_id=work_id, score=score, duration=duration) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error(traceback.format_exc()) finally: service.close() return res
def query_chuan_job_title(): res = {'code': 1000, 'msg': '成功'} data = request.json data = data.get('data') if not check_param(data): return handle_param_error() uid = data.get('userid') or 0 #duration = data.get('data').get('duration') or 0 vids = data.get('video_ids') or [] if not (uid and vids and len(vids)): logger.error('fail|userid or vid is null, return') return handle_param_error() s = ChuanService() try: result = s.query_title(uid=uid, vids=vids) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error( 'fail|exception|chuan/title/query request serve error|%s' % traceback.format_exc()) finally: s.close() return res
def add_history(): res = {'code': 1000, 'msg': 'success'} data = request.json data = data.get('data') if not data: return handle_param_error() user_id = data.get("userid") or 0 video_id = data.get("video_id") or '' duration = data.get("duration") or 0 if not (user_id and video_id): return handle_param_error() service = HistoryService() try: result = service.add_history(user_id=user_id, video_id=video_id, duration=duration) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|add history request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_content_list(): 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 page_num = data.get("page_num") or 1 type_class = data.get("type") or 'all' type_id = data.get("type_id") or 'all' tag = data.get("tag") or 'all' service = VideoService() try: result = service.get_class_video(page_num, type_class, type_id, tag) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|game video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_watch_users(): 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 page_num = data.get("page_num") or 1 if not user_id or not page_num: return handle_param_error() service = WatchService() try: result = service.get_watch(user_id=user_id, page_num=page_num) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|watch video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_weixin_signature(): res = {'code':1000,'msg':'success','data':{}} logger.info('get a weixin signature req') try: token_serv = WeiXinLoginService(appid=WX_APP_ID, secret=WX_APP_SECRET) data = token_serv.get_signature() if not data: logger.info('fail|get_signature fail.') #res['code'] = -1 #res['msg'] = 'signature fail' return handle_failure() result = {} result['signature'] = data[0] result['ts'] = data[1] result['noncestr'] = data[2] #data['userinfo'] = obj res = handle_success(result, 1000, '成功') logger.info('get weixin signature response:%s'%result) except: res = handle_failure() logger.error('fail|exception|ub request serve error|%s' % traceback.format_exc()) finally: pass 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_user_chuan_video(): 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 req_user_id = data.get("req_user_id") or 0 page_num = data.get("page_num") or 1 if not user_id: return handle_param_error() service = VideoService() try: result = service.get_chuan_video_by_user(user_id, req_user_id, page_num) res = handle_success(result, 1000, '成功') logger.info('success|user chuan video list request serve success') except: res = handle_failure() logger.error('fail|exception|userc huan video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_users_video(): 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_ids = data.get("req_user_ids") or 0 batch_num = data.get("batch_num") or 11 if not user_id: return handle_param_error() service = VideoService() try: result = service.get_video_by_users(user_id=user_id, req_user_ids=req_user_ids, batch_num=batch_num) if not result: return handle_param_error() res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|user video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_watch_list(): logger.info('rec a watch video list request') res = {'code': 1000, 'msg': '成功'} data = request.json logger.info('request data => {0}'.format(data)) data = data.get('data') if not check_param(data): return handle_param_error() user_id = data.get("userid") or 0 page_num = data.get("page_num") or 1 if not user_id or not page_num or not check_param(data): return handle_param_error() service = WatchService() try: result = service.get_watch_video(user_id, page_num) res = handle_success(result, 1000, '成功') logger.info('success|watch video list request serve success') except: res = handle_failure() logger.error('fail|exception|watch video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def _list_music_works(music_id='', tp=0): res = {'code': 1000, 'msg': '成功'} service = DanceService() try: result = service.get_works_by_music_id(music_id=music_id, tp=tp) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error(traceback.format_exc()) finally: service.close() return res
def get_all_game(): res = {'code': 1000, 'msg': '成功'} service = TagService() try: result = service.get_all_content() res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|game list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def list_category(): res = {'code': 1000, 'msg': '成功'} service = CategoryService() try: result = service.get_categorys() res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|category request serve error|%s' % traceback.format_exc()) finally: service.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 _list_work_dancers(work_id=0, dance_id=0, tp=0, user_id=0): res = {'code': 1000, 'msg': '成功'} if not (dance_id or work_id): return handle_param_error() service = DanceService() try: result = service.get_dancers_by_work_id(work_id=work_id, dance_id=dance_id, tp=tp, user_id=0) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error(traceback.format_exc()) finally: service.close() return res
def list_music(): res = {'code' : 1000, 'msg' : '成功'} data = request.json data = data.get("data") if data: user_id = data.get("userid") or 0 service = MediaService() try: result = service.get_music(user_id) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|music list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_discover_video(): res = {'code' : 1000, 'msg' : '成功'} data = request.json command = data.get("cmd") or '' data = data.get('data') if data else None if not data: return handle_param_error() page_num = data.get("page_num") or 1 service = VideoService() try: result = service.get_discover_video(page_num) res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|discover video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res
def get_index_video(): 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 service = VideoService() try: result = service.get_hot_video() res = handle_success(result, 1000, '成功') except: res = handle_failure() logger.error('fail|exception|hot video list request serve error|%s' % traceback.format_exc()) finally: service.close() return res