优化登录掉线
							parent
							
								
									43799d3b56
								
							
						
					
					
						commit
						fa85652feb
					
				| 
						 | 
					@ -91,7 +91,7 @@ class CDNProxy:
 | 
				
			||||||
                            f.write(json.dumps(local_dict)+"\n")
 | 
					                            f.write(json.dumps(local_dict)+"\n")
 | 
				
			||||||
                            num += 1
 | 
					                            num += 1
 | 
				
			||||||
            except Exception as e:
 | 
					            except Exception as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
        print(u"本次cdn获取完成,总个数{0}".format(num))
 | 
					        print(u"本次cdn获取完成,总个数{0}".format(num))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def all_cdn(self):
 | 
					    def all_cdn(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -53,6 +53,7 @@ urls = {
 | 
				
			||||||
        "s_time": 0.1,
 | 
					        "s_time": 0.1,
 | 
				
			||||||
        "is_logger": False,
 | 
					        "is_logger": False,
 | 
				
			||||||
        "is_json": False,
 | 
					        "is_json": False,
 | 
				
			||||||
 | 
					        "not_decode": True,
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "codeCheck": {  # 验证码校验
 | 
					    "codeCheck": {  # 验证码校验
 | 
				
			||||||
        "req_url": "/passport/captcha/captcha-check",
 | 
					        "req_url": "/passport/captcha/captcha-check",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,11 +62,11 @@ class select:
 | 
				
			||||||
        :return:
 | 
					        :return:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        ticket_info_config = _get_yaml()
 | 
					        ticket_info_config = _get_yaml()
 | 
				
			||||||
        from_station = ticket_info_config["set"]["from_station"].encode("utf8")
 | 
					        from_station = ticket_info_config["set"]["from_station"]
 | 
				
			||||||
        to_station = ticket_info_config["set"]["to_station"].encode("utf8")
 | 
					        to_station = ticket_info_config["set"]["to_station"]
 | 
				
			||||||
        station_dates = ticket_info_config["set"]["station_dates"]
 | 
					        station_dates = ticket_info_config["set"]["station_dates"]
 | 
				
			||||||
        set_names = ticket_info_config["set"]["set_type"]
 | 
					        set_names = ticket_info_config["set"]["set_type"]
 | 
				
			||||||
        set_type = [seat_conf[x.encode("utf8")] for x in ticket_info_config["set"]["set_type"]]
 | 
					        set_type = [seat_conf[x.encode("utf-8")] for x in ticket_info_config["set"]["set_type"]]
 | 
				
			||||||
        is_more_ticket = ticket_info_config["set"]["is_more_ticket"]
 | 
					        is_more_ticket = ticket_info_config["set"]["is_more_ticket"]
 | 
				
			||||||
        ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
 | 
					        ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
 | 
				
			||||||
        station_trains = ticket_info_config["set"]["station_trains"]
 | 
					        station_trains = ticket_info_config["set"]["station_trains"]
 | 
				
			||||||
| 
						 | 
					@ -179,13 +179,14 @@ class select:
 | 
				
			||||||
        l.reqLiftTicketInit()
 | 
					        l.reqLiftTicketInit()
 | 
				
			||||||
        self.call_login()
 | 
					        self.call_login()
 | 
				
			||||||
        check_user = checkUser(self)
 | 
					        check_user = checkUser(self)
 | 
				
			||||||
        check_user.sendCheckUser()
 | 
					        t = threading.Thread(target=check_user.sendCheckUser)
 | 
				
			||||||
 | 
					        t.setDaemon(True)
 | 
				
			||||||
 | 
					        t.start()
 | 
				
			||||||
        from_station, to_station = self.station_table(self.from_station, self.to_station)
 | 
					        from_station, to_station = self.station_table(self.from_station, self.to_station)
 | 
				
			||||||
        num = 0
 | 
					        num = 0
 | 
				
			||||||
        while 1:
 | 
					        while 1:
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                num += 1
 | 
					                num += 1
 | 
				
			||||||
                check_user.sendCheckUser()
 | 
					 | 
				
			||||||
                now = datetime.datetime.now()  # 感谢群里大佬提供整点代码
 | 
					                now = datetime.datetime.now()  # 感谢群里大佬提供整点代码
 | 
				
			||||||
                if now.hour >= 23 or now.hour < 6:
 | 
					                if now.hour >= 23 or now.hour < 6:
 | 
				
			||||||
                    print(u"12306休息时间,本程序自动停止,明天早上七点将自动运行")
 | 
					                    print(u"12306休息时间,本程序自动停止,明天早上七点将自动运行")
 | 
				
			||||||
| 
						 | 
					@ -277,31 +278,31 @@ class select:
 | 
				
			||||||
                                                                                                                random_time))
 | 
					                                                                                                                random_time))
 | 
				
			||||||
                    time.sleep(random_time)
 | 
					                    time.sleep(random_time)
 | 
				
			||||||
            except PassengerUserException as e:
 | 
					            except PassengerUserException as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except ticketConfigException as e:
 | 
					            except ticketConfigException as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except ticketIsExitsException as e:
 | 
					            except ticketIsExitsException as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except ticketNumOutException as e:
 | 
					            except ticketNumOutException as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except UserPasswordException as e:
 | 
					            except UserPasswordException as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
                break
 | 
					                break
 | 
				
			||||||
            except ValueError as e:
 | 
					            except ValueError as e:
 | 
				
			||||||
                if e.message == "No JSON object could be decoded":
 | 
					                if e == "No JSON object could be decoded":
 | 
				
			||||||
                    print(u"12306接口无响应,正在重试")
 | 
					                    print(u"12306接口无响应,正在重试")
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    print(e.message)
 | 
					                    print(e)
 | 
				
			||||||
            except KeyError as e:
 | 
					            except KeyError as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
            except TypeError as e:
 | 
					            except TypeError as e:
 | 
				
			||||||
                print(u"12306接口无响应,正在重试 {0}".format(e.message))
 | 
					                print(u"12306接口无响应,正在重试 {0}".format(e))
 | 
				
			||||||
            except socket.error as e:
 | 
					            except socket.error as e:
 | 
				
			||||||
                print(e.message)
 | 
					                print(e)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,7 @@ class checkUser:
 | 
				
			||||||
        :return:
 | 
					        :return:
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        CHENK_TIME = 0.3
 | 
					        CHENK_TIME = 0.3
 | 
				
			||||||
 | 
					        while 1:
 | 
				
			||||||
            if wrapcache.get("user_time") is None:
 | 
					            if wrapcache.get("user_time") is None:
 | 
				
			||||||
                check_user_url = self.session.urls["check_user_url"]
 | 
					                check_user_url = self.session.urls["check_user_url"]
 | 
				
			||||||
                data = {"_json_att": ""}
 | 
					                data = {"_json_att": ""}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,8 +5,6 @@ from collections import OrderedDict
 | 
				
			||||||
from time import sleep
 | 
					from time import sleep
 | 
				
			||||||
import requests
 | 
					import requests
 | 
				
			||||||
from config import logger
 | 
					from config import logger
 | 
				
			||||||
import wrapcache
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _set_header_default():
 | 
					def _set_header_default():
 | 
				
			||||||
    header_dict = OrderedDict()
 | 
					    header_dict = OrderedDict()
 | 
				
			||||||
| 
						 | 
					@ -137,11 +135,16 @@ class HTTPClient(object):
 | 
				
			||||||
                                           verify=False,
 | 
					                                           verify=False,
 | 
				
			||||||
                                           **kwargs)
 | 
					                                           **kwargs)
 | 
				
			||||||
                if response.status_code == 200 or response.status_code == 302:
 | 
					                if response.status_code == 200 or response.status_code == 302:
 | 
				
			||||||
 | 
					                    if urls.get("not_decode", False):
 | 
				
			||||||
 | 
					                        return response.content
 | 
				
			||||||
                    if response.content:
 | 
					                    if response.content:
 | 
				
			||||||
                        if is_logger:
 | 
					                        if is_logger:
 | 
				
			||||||
                            logger.log(
 | 
					                            logger.log(
 | 
				
			||||||
                                u"出参:{0}".format(response.content))
 | 
					                                u"出参:{0}".format(response.content))
 | 
				
			||||||
                        return json.loads(response.content) if urls["is_json"] else response.content
 | 
					                        if urls["is_json"]:
 | 
				
			||||||
 | 
					                            return json.loads(response.content.decode() if isinstance(response.content, bytes) else response.content)
 | 
				
			||||||
 | 
					                        else:
 | 
				
			||||||
 | 
					                            return response.content.decode("utf8", "ignore") if isinstance(response.content, bytes) else response.content
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
                        logger.log(
 | 
					                        logger.log(
 | 
				
			||||||
                            u"url: {} 返回参数为空".format(urls["req_url"]))
 | 
					                            u"url: {} 返回参数为空".format(urls["req_url"]))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue