Beispiel #1
0
 def buy_ticket_five(repeat_submit_token, name, passenger_type, id_num, phone_num, category):
     # # 验证有没有登录成功
     # # 个人中心链接
     # url = 'https://kyfw.12306.cn/otn/index/initMy12306'
     # response = session.get(url, headers=headers)
     # if response.status_code == 200:
     #     html = response.text
     #     print(html)
     category = seat_to_int[category]
     url = 'https://kyfw.12306.cn/otn/confirmPassenger/checkOrderInfo'
     data = {
         '_json_att': '',
         'bed_level_order_num': '000000000000000000000000000000',
         'cancel_flag': '2',
         'oldPassengerStr': '{},1,{},3_'.format(name, id_num),
         'passengerTicketStr': '{},0,{},{},1,{},{},N'.format(category, passenger_type, name, id_num, phone_num),
         'randCode': '',
         'REPEAT_SUBMIT_TOKEN': repeat_submit_token,
         'tour_flag': 'dc',
         'whatsSelect': '1'
     }
     # print(data)
     response = session.post(url, headers=headers, data=data)
     # print(response)
     if response.status_code == 200:
         html = response.text
         # print(html)
         data = json.loads(html)
         print('100009:', data)
         if data['data']['submitStatus'] is True:
             return False
Beispiel #2
0
 def buy_ticket_six(train_location, key_check_is_change, left_ticket_str, repeat_submit_token,
                    name, id_num, phone_num, category):
     category = seat_to_int[category]
     url = 'https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue'
     data = {
         '_json_att': '',
         'choose_seats': '',
         'dwAll': 'N',
         'key_check_isChange': key_check_is_change,
         'leftTicketStr': left_ticket_str,
         'oldPassengerStr': '{},1,{},3_'.format(name, id_num),
         'passengerTicketStr': '{},0,1,{},1,{},{},N'.format(category, name, id_num, phone_num),
         'purpose_codes': '00',
         'randCode': '',
         'REPEAT_SUBMIT_TOKEN': repeat_submit_token,
         'roomType': '00',
         'seatDetailType': '000',
         'train_location': train_location,
         'whatsSelect': '1'
     }
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('1000010:', data)
Beispiel #3
0
 def buy_ticket_two(self, secret_str):
     """
     下单的第二个请求
     :param secret_str:
     :return:
     """
     url = 'https://kyfw.12306.cn/otn/leftTicket/submitOrderRequest'
     today = datetime.datetime.now()
     back_train_date = str(today)[:10]
     data = {
         'back_train_date': back_train_date,
         'purpose_codes': 'ADULT',
         'query_from_station_name': self.from_station,
         'query_to_station_name': self.to_station,
         'secretStr': unquote(secret_str),
         'tour_flag': 'dc',
         'train_date': self.train_date,
         'undefined': ''
     }
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('100007:', data)
         if '未处理的订单' in str(data['messages']):
             print('您还有未处理的订单!!,请您先处理完未完成的订单在进行抢票!!')
             return None
         if data['status'] is True:
             return True
Beispiel #4
0
 def buy_ticket_seven(train_location, key_check_is_change, left_ticket_str,
                      repeat_submit_token, name, id_num, phone_num,
                      category, is_adult):
     """
     下单的第七个请求
     :param train_location:
     :param key_check_is_change:
     :param left_ticket_str:
     :param repeat_submit_token:
     :param name:
     :param id_num:
     :param phone_num:
     :param category:
     :param is_adult:
     :return:
     """
     if is_adult is True:
         passenger_type = '1'
     else:
         passenger_type = '3'
     category = seat_to_int[category]
     url = 'https://kyfw.12306.cn/otn/confirmPassenger/confirmSingleForQueue'
     data = {
         '_json_att':
         '',
         'choose_seats':
         '',
         'dwAll':
         'N',
         'key_check_isChange':
         key_check_is_change,
         'leftTicketStr':
         left_ticket_str,
         'oldPassengerStr':
         '{},{},{},{}_'.format(name, passenger_type, id_num,
                               passenger_type),
         'passengerTicketStr':
         '{},0,{},{},1,{},{},N'.format(category, passenger_type, name,
                                       id_num, phone_num),
         'purpose_codes':
         '00',
         'randCode':
         '',
         'REPEAT_SUBMIT_TOKEN':
         repeat_submit_token,
         'roomType':
         '00',
         'seatDetailType':
         '000',
         'train_location':
         train_location,
         'whatsSelect':
         '1'
     }
     print(data)
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('1000011:', data)
Beispiel #5
0
 def buy_ticket_six(self, from_station_code, left_ticket_str,
                    repeat_submit_token, category, train_code,
                    to_station_code, train_location, train_no):
     category = seat_to_int[category]
     train_data = self.get_train_data.get_week_day()
     url = 'https://kyfw.12306.cn/otn/confirmPassenger/getQueueCount'
     data = {
         '_json_att': '',
         'fromStationTelecode': from_station_code,
         'leftTicket': left_ticket_str,
         'purpose_codes': '00',
         'REPEAT_SUBMIT_TOKEN': repeat_submit_token,
         'seatType': category,
         'stationTrainCode': train_code,
         'toStationTelecode': to_station_code,
         'train_date': train_data + ' 00:00:00 GMT+0800',
         'train_location': train_location,
         'train_no': train_no,
     }
     print(data)
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('100000010:', data)
Beispiel #6
0
 def __search_result_order(self):
     self.result_order = {
         'orderSequence_no': 'EC16649156',
         '_json_att': '',
         'REPEAT_SUBMIT_TOKEN': self.repeat_submit_order
     }
     res = session.post(Api.result_order, data=self.result_order)
     print(res.content.decode('utf-8'))
Beispiel #7
0
 def buy_ticket_one():
     url = 'https://kyfw.12306.cn/otn/login/checkUser'
     data = {
         '_json_att': ''
     }
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('100006:', data)
Beispiel #8
0
 def buy_ticket_three():
     url = 'https://kyfw.12306.cn/otn/confirmPassenger/initDc'
     data = {
         '_json_att': ''
     }
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         # print(html)
         result1 = re.findall("globalRepeatSubmitToken = '(.*?)';", html)[0]
         result2 = re.findall("'key_check_isChange':'(.*?)',", html)[0]
         result3 = re.findall("'leftTicketStr':'(.*?)',", html)[0]
         return result1, result2, result3
Beispiel #9
0
 def buy_ticket_four(repeat_submit_token):
     url = 'https://kyfw.12306.cn/otn/confirmPassenger/getPassengerDTOs'
     data = {
         '_json_att': '',
         'REPEAT_SUBMIT_TOKEN': repeat_submit_token
     }
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('100008:', data)
         if data and 'data' in data.keys():
             normal_passengers = data['data']['normal_passengers'][0]
             return normal_passengers['passenger_name'], normal_passengers['passenger_id_no'], \
                 normal_passengers['passenger_type'], normal_passengers['mobile_no']
Beispiel #10
0
 def __get_queue_count(self):
     self.seats = {
         'train_date': 'Wed Jan 23 2019 00:00:00 GMT+0800 (中国标准时间)',
         'train_no': self.train_no,
         'stationTrainCode': self.train_code,
         'seatType': 'O',
         'fromStationTelecode': self.from_station,
         'toStationTelecode': self.to_station,
         'leftTicket': self.left_ticket_str,
         'purpose_codes': '00',
         'train_location': self.train_location,
         '_json_at': '',
         'REPEAT_SUBMIT_TOKEN': self.repeat_submit_order
     }
     res = session.post(Api.confirm_passengers, data=self.seats)
     print(res.content.decode('utf-8'))
Beispiel #11
0
 def __check_order_info(self):
     self.__check = {
         'cancel_flag': 2,
         'bed_level_order_num': '000000000000000000000000000000',
         'passengerTicketStr':
         'O,0,1,张霖,1,430223199501291851,13813456184,N',
         'oldPassengerStr': '张霖,1,430223199501291851,1_',
         'tour_flag': 'dc',
         'randCode': '',
         '_json_att': '',
         'whatsSelect': '1',
         'REPEAT_SUBMIT_TOKEN': self.repeat_submit_order
     }
     res = session.post(Api.check_order_info, data=self.__check)
     print('res.content : %s ' % res.content.decode('utf-8'))
     self.__get_queue_count()
Beispiel #12
0
 def buy_ticket_one():
     """
     下单的第一个请求
     :return:
     """
     # # 验证有没有登录成功
     # # 个人中心链接
     # url = 'https://kyfw.12306.cn/otn/index/initMy12306'
     # response = session.get(url, headers=headers)
     # if response.status_code == 200:
     #     html = response.text
     #     print(html)
     # exit()
     url = 'https://kyfw.12306.cn/otn/login/checkUser'
     data = {'_json_att': ''}
     response = session.post(url, headers=headers, data=data)
     if response.status_code == 200:
         html = response.text
         data = json.loads(html)
         print('100006:', data)
Beispiel #13
0
 def __confirm_submit_order(self):
     self.confirm_order = {
         'passengerTicketStr': 'O,0,1,张霖,1,430223199501291851,13813456184',
         'oldPassengerStr': '张霖,1,430223199501291851,1_',
         'randCode': '',
         'purpose_codes': '00',
         'key_check_isChange': self.key_check_ischange,
         'leftTicketStr': self.left_ticket_str,
         'train_location': self.train_location,
         'choose_seats': '1F',
         'seatDetailType': '000',
         'roomType': '00',
         'dwAll': 'N',
         '_json_att': '',
         'whatsSelect': '1',
         'REPEAT_SUBMIT_TOKEN': self.repeat_submit_order
     }
     res = session.post(Api.confirm_order, data=self.confirm_order)
     print(res.content.decode('utf-8'))
     send_email.send_email()
     self.__search_result_order()
Beispiel #14
0
    def __init_dc(self):
        self.__dc = {'_json_att': ''}
        res = session.post(Api.init_dc, data=self.__dc)
        content = res.content.decode('utf-8')
        with open('dc.html', 'w', encoding='utf-8') as f:
            f.write(content)
        point = content.find('globalRepeatSubmitToken')
        repeat_submit_token = res.content.decode('utf-8')[point + 27:point +
                                                          59]
        point2 = content.find('leftTicketStr')
        if point2 != -1:
            middle_data = content[point2 + 16:]
            left_ticket_str = middle_data[0:middle_data.find('\'')]
            self.left_ticket_str = left_ticket_str
        self.repeat_submit_order = repeat_submit_token

        point3 = content.find('key_check_isChange')
        key_check_ischange = content[point3 + 21:point3 + 77]
        print(key_check_ischange)
        self.key_check_ischange = key_check_ischange

        if hasattr(self, 'left_ticket_str'):
            self.__check_order_info()
Beispiel #15
0
 def output_passengers(self):
     res = session.post(Api.passengers, data=self.__page)
     with open('passengers.json', 'w', encoding='utf-8') as f:
         f.write(res.text)
Beispiel #16
0
 def __submit_order_request(self):
     session.post(Api.submit_order, data=self.data)