def run_query(self): params = { r'leftTicketDTO.train_date': self.travel_date, r'leftTicketDTO.from_station': CityData.find_city_by_name(self.from_station).code, r'leftTicketDTO.to_station': CityData.find_city_by_name(self.to_station).code, r'purpose_codes': find_by_name("ticket", Config.basic_config.ticket_type).sys_code } json_response = send_requests(LOGIN_SESSION, QUERY_URL_MAPPING, params=params) if not isinstance(json_response, dict): return [] try: if "data" in json_response and "result" in json_response['data']: return [ TrainDetail(v.split('|')) for v in json_response['data']['result'] ] or [] else: return [] except KeyError: return []
def _get_queue_count_async(self): form_data = { 'train_date': datetime.datetime.strptime( self.train.train_date.value, '%Y%m%d').strftime('%b %a %d %Y 00:00:00 GMT+0800') + ' (中国标准时间)', 'train_no': self.train.sys_train_no.value, 'stationTrainCode': self.train.stationTrainCode.value, 'seatType': self.seat_type.sys_code, 'fromStationTelecode': self.train.from_station_code.value, 'toStationTelecode': self.train.to_station_code.value, 'leftTicket': self.ticket_passenger_info['leftTicketStr'], 'purpose_codes': find_by_name("ticket", Config.basic_config.ticket_type).sys_code, '_json_att': '' } json_response = send_requests(LOGIN_SESSION, self.URLS['getQueueCountAsync'], data=form_data) status, msg = submit_response_checker(json_response, ["status"], True) if not status: BlackTrains.add_train(self.train) return status, msg
def _auto_submit_order_request(self): """ # response example. for debug. {'validateMessagesShowId': '_validatorMessage', 'status': True, 'httpstatus': 200, 'data': {'result': 'QX#F7F13745AA1C7631B9C6B204C3677E3E1B654BE1111F558326BFED9D#hcc983%2Bc27menDVKU5ja2C2Q1%2FbToZXgLI1l8950QBZxtWwE#1', 'ifShowPassCode': 'N', 'canChooseBeds': 'N', 'canChooseSeats': 'Y', 'choose_Seats': 'M9', 'isCanChooseMid': 'N', 'ifShowPassCodeTime': '2985', 'submitStatus': True, 'smokeStr': ''}, 'messages': [], 'validateMessages': {}} :return: """ data = OrderedDict() data["secretStr"] = self.decode_secret_str(self.train.secretStr.value) data["train_date"] = self.format_date(self.train.train_date.value) data["tour_flag"] = "dc" data["purpose_codes"] = find_by_name( "ticket", Config.basic_config.ticket_type).sys_code data["query_from_station_name"] = self.train.from_station.value.name data["query_to_station_name"] = self.train.to_station.value.name data["cancel_flag"] = 2 data["bed_level_order_num"] = "000000000000000000000000000000" data["passengerTicketStr"] = build_passenger_ticket_string( self.seat_type, self.passenger_data) data["oldPassengerStr"] = build_oldpassenger_ticket_string( self.passenger_data) json_response = send_requests(LOGIN_SESSION, self.URLS['autoSubmitOrderRequest'], data=data) status, msg = submit_response_checker(json_response, ["status", "data.submitStatus"], True) if status: self.ticket_passenger_info = dict( zip(["train_location", "key_check_isChange", "leftTicketStr"], [ unquote(v) for v in json_response["data"]["result"].split("#") ])) return status, msg
def _confirm_single_for_queue_asys(self): form_data = OrderedDict() form_data['passengerTicketStr'] = build_passenger_ticket_string( self.seat_type, self.passenger_data) form_data['oldPassengerStr'] = build_oldpassenger_ticket_string( self.passenger_data) form_data['randCode'] = '' form_data['purpose_codes'] = find_by_name( "ticket", Config.basic_config.ticket_type).sys_code form_data['key_check_isChange'] = self.ticket_passenger_info[ 'key_check_isChange'] form_data['leftTicketStr'] = self.ticket_passenger_info[ 'leftTicketStr'] form_data['train_location'] = self.ticket_passenger_info[ 'train_location'] form_data['choose_seats'] = '' form_data['seatDetailType'] = '' form_data['_json_att'] = '' json_response = send_requests(LOGIN_SESSION, self.URLS['confirmSingleForQueueAsys'], data=form_data) status, msg = submit_response_checker(json_response, ["status", "data.submitStatus"], True) return status, msg
def _auto_submit_order_request(self): """ :return: status, msg """ data = OrderedDict() data["secretStr"] = self.decode_secret_str(self.train.secretStr.value) data["train_date"] = self.format_date(self.train.train_date.value) data["tour_flag"] = "dc" data["purpose_codes"] = find_by_name( "ticket", Config.basic_config.ticket_type).sys_code data["query_from_station_name"] = self.train.from_station.value.name data["query_to_station_name"] = self.train.to_station.value.name data["cancel_flag"] = 2 data["bed_level_order_num"] = "000000000000000000000000000000" data["passengerTicketStr"] = build_passenger_ticket_string( self.seat_type, self.passenger_data) data["oldPassengerStr"] = build_oldpassenger_ticket_string( self.passenger_data) json_response = send_requests(LOGIN_SESSION, self.URLS['autoSubmitOrderRequest'], data=data) status, msg = submit_response_checker(json_response, ["status", "data.submitStatus"], True) if status: self.ticket_passenger_info = dict( zip(["train_location", "key_check_isChange", "leftTicketStr"], [ unquote(v) for v in json_response["data"]["result"].split("#") ])) return status, msg
def build_passenger_ticket_string(seat_type, passengers): # 1(seatType),0,1(车票类型:ticket_type_codes),张三(passenger_name),1(证件类型:passenger_id_type_code),320xxxxxx(passenger_id_no),151xxxx(mobile_no),N f = lambda x: '%s,0,%s,%s,%s,%s,%s,N' % ( seat_type.sys_code, find_by_name("ticket", Config.basic_config.ticket_type ).user_code, x.passenger_name, x.passenger_id_type_code, x .passenger_id_no, x.mobile_no) return '_'.join([f(v) for v in passengers])
def _submit_order_request(self): """ :return: """ form_data = { 'secretStr': self.decode_secret_str(self.train.secretStr.value), 'train_date': self.format_date(self.train.train_date.value), # 车票时间 'back_train_date': time.strftime("%Y-%m-%d", time.localtime()), # query date:2017-12-31 'tour_flag': 'dc', 'purpose_codes': find_by_name("ticket", Config.basic_config.ticket_type).sys_code, 'query_from_station_name': self.train.from_station.value.name, 'query_to_station_name': self.train.to_station.value.name, 'undefined': '', } Log.v("请求预提交订单") json_response = send_requests(LOGIN_SESSION, self.URLS['submitOrderRequest'], data=form_data) status, msg = submit_response_checker(json_response, ["status"], True, "请求预提交订单成功") if "messages" in json_response: print(json_response["messages"]) print(''.join(json_response["messages"])) if "messages" in json_response and ORDER_NOT_FINISHED_MESSAGE['msg'] in ''.join(json_response["messages"]): self.unfinished_order = True return status, msg
def build_oldpassenger_ticket_string(passengers): # oldPassengerStr-->张三(passenger_name),1(证件类型:passenger_id_type_code),320xxxxxx(passenger_id_no),1_ f = lambda x: '%s,%s,%s,%s_' % ( x.passenger_name, x.passenger_id_type_code, x.passenger_id_no, find_by_name("ticket", Config.basic_config.ticket_type).user_code) return '_'.join([f(v) for v in passengers])