コード例 #1
0
def get_openid_by_uuid(uuid=0, uin=0):
    #need ask them l5.
    udp_client = UDPClient(host='10.239.196.159', port=15000)
    try:
        qt = QtHelper()
        sess = qt.createSessInfo(pb_openid.CMD_TICKETSVR,
                                 pb_openid.SUBCMD_PARSE_ID, 8031, uin)

        req = pb_openid.ParseIdReq()
        req.ids.extend([uuid])

        res = qt.buildSendPkg(sess, req)

        udp_client.sendData(buf=res.serialize())
        bb = udp_client.recvData()

        resp = qt.parseReceivePkg(bb)
        resp.unserialize()
        resp_str = str(buffer(resp.body_str)[:])
        pb_resp = pb_openid.ParseIdRsp()
        pb_resp.ParseFromString(resp_str)

        return pb_resp
    except:
        logger.error('get error:%s' % traceback.format_exc())
    finally:
        udp_client.close()
コード例 #2
0
    def get_videos_by_batch_users(self, batch_num=5, game_ids=None, appid='wx9ce8f64a4c9b3308', uin=0, openids=[], uins=[], ip='', port=0):
        #if not game_ids:
        #    game_ids = [2103041,1007058,1007039,1007044,1007042,1007053,1007060]
        if not (ip and port):
            modid,cmdid = read_l5_info()
            ip,port = get_router(modid, cmdid)

        if not (ip and port):
            logger.error('ip or port is null')
            return []

        udp_client = UDPClient(host=ip, port=port)
        end_sec    = 0
        end_usec   = 0
        obj_arr = []

        try:
            for item in openids:
                uid        = item.get('uid') or ''
                if not uid:
                    continue
                begin_sec  = item.get('begin_sec') or 0
                begin_usec = item.get('begin_usec') or 0

                fetcher.info('get_videos_by_batch_users start, begin_sec:%s,begin_usec:%s,batch_num:%s,openid:%s'%(begin_sec,begin_usec,batch_num,uid))
                buf = self.build_multi_game_send_buf(game_ids=game_ids,
                                                       begin_sec=begin_sec,begin_usec=begin_usec,batch_num=batch_num,
                                                       uin=uin,v_type=0,openid=uid)
                udp_client.sendData(buf=buf)

            for item in uins:
                uid        = item.get('uid') or ''
                if not uid:
                    continue
                begin_sec  = item.get('begin_sec') or 0
                begin_usec = item.get('begin_usec') or 0

                fetcher.info('get_videos_by_batch_users start, begin_sec:%s,begin_usec:%s,batch_num:%s,uin:%s'%(begin_sec,begin_usec,batch_num,uid))
                buf = self.build_multi_game_send_buf(game_ids=game_ids,
                                                       begin_sec=begin_sec,begin_usec=begin_usec,batch_num=batch_num,
                                                       uin=uid,v_type=0)
                udp_client.sendData(buf=buf)

            loops = len(openids) + len(uins)
            while loops > 0:
                uid_datas = {'uid':'','end_sec':0, 'end_usec':0, 'datas':[]}
                loops -= 1
                resp = self.recv_multi_game_resp(udp_client)

                if not resp:
                    fetcher.error('get_videos_by_batch_users error, resp is null')
                    continue
                if resp.result != 0:
                    fetcher.error('get_videos_by_batch_users error, resp.resp is not 0:%s'%resp)
                    continue
                fetcher.info('get:%s %sitems of get_videos_by_batch_users in fact' % (resp.flag,len(resp.video_list)))
                end_sec  = resp.end_sec
                end_usec = resp.end_usec
                flag     = resp.flag

                for info in resp.video_list:
                    v_obj = assemble_v_obj(info, None, appid, flag=False)
                    if not v_obj:
                        continue
                    uid_datas['datas'].append(v_obj)
                uid_datas['end_sec']  = end_sec
                uid_datas['end_usec'] = end_usec
                uid_datas['uid']      = flag
                obj_arr.append(uid_datas)

        except:
            logger.error(traceback.format_exc())
        finally:
            udp_client.close()
            return obj_arr