def main(): f = open('140920.txt') while True: line = f.readline() if not line: break log = line.strip().lstrip('{').rstrip('}') #print(log) info = log.split(',') k_v = {} for data in info: element = data.split(': ') if len(element) <= 1: break key = element[0].strip().strip('\'') val = element[1].strip().strip('\'') k_v[key] = val if k_v['code'] == 'A': output = make_a(k_v) if k_v['code'] == 'B': output = make_b(k_v) print(output) printer.warning(output) #break f.close() printer.wait_for_flush()
def update_status(self): global global_info udp_recv = self.recv_udp() if udp_recv == None: return udp_recv = self.proto.parse_decode(udp_recv) info_val = self.proto.parse_ack(udp_recv) if info_val == None: return code = info_val['code'] if code == 'F': printer.debug(udp_recv) return if code == 'C': printer.info(udp_recv) return if code == 'A' or code == 'B': printer.warning(udp_recv) printer.error(udp_recv) return printer.error(udp_recv) return
def do_login(self): global channel_center proto = self.client.proto req = proto.make_login_req() for i in range(self.max_retry): channel_center.login_request_increase() group, channel = channel_center.get_channel('login') channel_center.login_request_decrease() if channel == None: continue head = proto.make_ssl_head(server_dict[group]['login']['name']) info_val = channel_center.pyget(channel, req, head) if info_val == None: continue if info_val['status'] != 200: printer.error('client %s fd_login status %s' % (self.client.bidno, info_val['status'])) continue ack_val = proto.parse_login_ack(info_val['body']) if 'pid' not in ack_val or 'name' not in ack_val: printer.error('client %s fd_login ack error %s' % (self.client.bidno, str(info_val))) continue self.client.pid_login = ack_val['pid'] self.client.name_login = ack_val['name'] printer.warning( 'client %s login %s %s' % (self.client.bidno, ack_val['name'], ack_val['pid'])) return True printer.warning('client %s login failed !!!') return False
def update_status(self): udp_recv = self.recv_udp() if udp_recv == None: return udp_recv = self.proto.parse_decode(udp_recv) info_val = self.proto.parse_ack(udp_recv) if info_val == None: return code = info_val['code'] if code == 'F': if self.console != None : self.console.update_udp_status(datetime.strftime(datetime.now(), '%H:%M:%S')) return bidinfo = info_val['bidinfo'] if code == 'C': if self.console != None : self.console.update_bid_status(bidinfo) return printer.critical(udp_recv) ctime = info_val['ltime'] stime = info_val['systime'] price = info_val['price'] try: int_price = int(price) except: print_exc() return global current_price current_price.set(int_price) self.check_shot_price(int_price) self.check_image_price(int_price, stime) if self.console != None : self.console.update_udp_info(ctime, stime, price) self.console.update_bid_status(bidinfo) printer.warning(info_val, True)
def do_bid(self): global global_info global_info.event_image[self.count].wait() price = global_info.trigger_price[self.count] for i in range(self.max_retry): self.client.picture_bid[self.count] = None thread_image = fd_image(self.client, self.count, price) thread_image.start() if thread_image.wait_for_finish() != True: continue if self.client.sid_bid[ self.count] == None or self.client.picture_bid[ self.count] == None: continue self.client.number_bid[self.count] = None thread_decode = fd_decode( self.client, self.count, self.client.bidno + self.client.sid_bid[self.count], self.client.picture_bid[self.count]) thread_decode.start() if thread_decode.wait_for_finish() != True: continue if self.client.number_bid[ self.count] == None or self.client.number_bid[ self.count] == '000000': continue break printer.warning( 'client %s bid %s image %s %s ' % (self.client.bidno, self.count, self.client.sid_bid[self.count], self.client.number_bid[self.count])) global_info.event_price[self.count].wait() self.client.price_bid[self.count] = None for i in range(self.max_retry): thread_price = [ fd_price(self.client, self.count, price, 0), fd_price(self.client, self.count, price, 1) ] thread_price[0].start() thread_price[1].start() sleep(self.bid_timeout) if global_info.flag_gameover == True: break if self.client.err_112[self.count] == True: printer.warning( 'client %s bid %s price %s meet err_112 %s %s' % (self.client.bidno, self.count, price, self.client.name_login, self.client.pid_login)) return if self.client.price_bid[self.count] == None: continue break printer.warning( 'client %s bid %s price %s %s %s' % (self.client.bidno, self.count, self.client.price_bid[self.count], self.client.name_login, self.client.pid_login))
def put_channel(self, channel, group, handle): printer.warning('put_channel : ' + str(group) + ' ' + str(handle)) time = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M:%S.%f') channel_handle_tuple = (time, handle) return self.queue[group][channel].put(channel_handle_tuple)