优化登录掉线

pull/73/head
wenxianping 2019-01-04 09:38:40 +08:00
parent 43799d3b56
commit fa85652feb
5 changed files with 40 additions and 34 deletions

View File

@ -91,7 +91,7 @@ class CDNProxy:
f.write(json.dumps(local_dict)+"\n")
num += 1
except Exception as e:
print(e.message)
print(e)
print(u"本次cdn获取完成总个数{0}".format(num))
def all_cdn(self):

View File

@ -53,6 +53,7 @@ urls = {
"s_time": 0.1,
"is_logger": False,
"is_json": False,
"not_decode": True,
},
"codeCheck": { # 验证码校验
"req_url": "/passport/captcha/captcha-check",

View File

@ -62,11 +62,11 @@ class select:
:return:
"""
ticket_info_config = _get_yaml()
from_station = ticket_info_config["set"]["from_station"].encode("utf8")
to_station = ticket_info_config["set"]["to_station"].encode("utf8")
from_station = ticket_info_config["set"]["from_station"]
to_station = ticket_info_config["set"]["to_station"]
station_dates = ticket_info_config["set"]["station_dates"]
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"]
ticke_peoples = ticket_info_config["set"]["ticke_peoples"]
station_trains = ticket_info_config["set"]["station_trains"]
@ -179,13 +179,14 @@ class select:
l.reqLiftTicketInit()
self.call_login()
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)
num = 0
while 1:
try:
num += 1
check_user.sendCheckUser()
now = datetime.datetime.now() # 感谢群里大佬提供整点代码
if now.hour >= 23 or now.hour < 6:
print(u"12306休息时间本程序自动停止,明天早上七点将自动运行")
@ -277,31 +278,31 @@ class select:
random_time))
time.sleep(random_time)
except PassengerUserException as e:
print(e.message)
print(e)
break
except ticketConfigException as e:
print(e.message)
print(e)
break
except ticketIsExitsException as e:
print(e.message)
print(e)
break
except ticketNumOutException as e:
print(e.message)
print(e)
break
except UserPasswordException as e:
print(e.message)
print(e)
break
except ValueError as e:
if e.message == "No JSON object could be decoded":
if e == "No JSON object could be decoded":
print(u"12306接口无响应正在重试")
else:
print(e.message)
print(e)
except KeyError as e:
print(e.message)
print(e)
except TypeError as e:
print(u"12306接口无响应正在重试 {0}".format(e.message))
print(u"12306接口无响应正在重试 {0}".format(e))
except socket.error as e:
print(e.message)
print(e)
if __name__ == '__main__':

View File

@ -15,6 +15,7 @@ class checkUser:
:return:
"""
CHENK_TIME = 0.3
while 1:
if wrapcache.get("user_time") is None:
check_user_url = self.session.urls["check_user_url"]
data = {"_json_att": ""}

View File

@ -5,8 +5,6 @@ from collections import OrderedDict
from time import sleep
import requests
from config import logger
import wrapcache
def _set_header_default():
header_dict = OrderedDict()
@ -137,11 +135,16 @@ class HTTPClient(object):
verify=False,
**kwargs)
if response.status_code == 200 or response.status_code == 302:
if urls.get("not_decode", False):
return response.content
if response.content:
if is_logger:
logger.log(
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:
logger.log(
u"url: {} 返回参数为空".format(urls["req_url"]))