mirror of https://github.com/testerSunshine/12306
parent
7d40223973
commit
829ec1163e
|
@ -246,21 +246,20 @@ class select:
|
||||||
检查用户是否达到订票条件
|
检查用户是否达到订票条件
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
# check_user_url = self.confUrl["check_user_url"]["req_url"]
|
check_user_url = self.confUrl["check_user_url"]["req_url"]
|
||||||
# data = dict(_json_att=None)
|
data = {"_json_att": ""}
|
||||||
# check_user = self.httpClint.send(check_user_url, data)
|
check_user = self.httpClint.send(check_user_url, data)
|
||||||
# check_user_flag = check_user['data']['flag']
|
check_user_flag = check_user['data']['flag']
|
||||||
is_login = self.call_login(auth=True)
|
if check_user_flag is True:
|
||||||
if "result_code" in is_login and is_login["result_code"] == 0:
|
|
||||||
self.is_check_user["user_time"] = datetime.datetime.now()
|
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||||
else:
|
else:
|
||||||
if "result_message" in is_login and is_login["result_message"]:
|
if check_user['messages']:
|
||||||
print ('用户检查失败:%s,可能未登录,可能session已经失效' % is_login["result_message"])
|
print ('用户检查失败:%s,可能未登录,可能session已经失效' % check_user['messages'][0])
|
||||||
print ('正在尝试重新登录')
|
print ('正在尝试重新登录')
|
||||||
self.call_login()
|
self.call_login()
|
||||||
self.is_check_user["user_time"] = datetime.datetime.now()
|
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||||
else:
|
else:
|
||||||
print ('用户检查失败: %s,可能未登录,可能session已经失效' % is_login)
|
print ('用户检查失败: %s,可能未登录,可能session已经失效' % check_user)
|
||||||
print ('正在尝试重新登录')
|
print ('正在尝试重新登录')
|
||||||
self.call_login()
|
self.call_login()
|
||||||
self.is_check_user["user_time"] = datetime.datetime.now()
|
self.is_check_user["user_time"] = datetime.datetime.now()
|
||||||
|
@ -633,14 +632,13 @@ class select:
|
||||||
def main(self):
|
def main(self):
|
||||||
self.call_login()
|
self.call_login()
|
||||||
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)
|
||||||
# if self.leftTicketLog(from_station, to_station):
|
|
||||||
self.check_user()
|
self.check_user()
|
||||||
num = 1
|
num = 1
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
num += 1
|
num += 1
|
||||||
if "user_time" in self.is_check_user and (datetime.datetime.now() - self.is_check_user["user_time"]).seconds/60 > 5:
|
if "user_time" in self.is_check_user and (datetime.datetime.now() - self.is_check_user["user_time"]).seconds/60 > 5:
|
||||||
# 十分钟检查一次用户是否登录
|
# 5分钟检查一次用户是否登录
|
||||||
self.check_user()
|
self.check_user()
|
||||||
time.sleep(self.select_refresh_interval)
|
time.sleep(self.select_refresh_interval)
|
||||||
if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00":
|
if time.strftime('%H:%M:%S', time.localtime(time.time())) > "23:00:00":
|
||||||
|
|
|
@ -87,6 +87,7 @@ class HTTPClient(object):
|
||||||
method = "get"
|
method = "get"
|
||||||
self.resetHeaders()
|
self.resetHeaders()
|
||||||
for i in range(10):
|
for i in range(10):
|
||||||
|
try:
|
||||||
response = self._s.request(method=method,
|
response = self._s.request(method=method,
|
||||||
timeout=10,
|
timeout=10,
|
||||||
url=url,
|
url=url,
|
||||||
|
@ -94,17 +95,14 @@ class HTTPClient(object):
|
||||||
allow_redirects=allow_redirects,
|
allow_redirects=allow_redirects,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
try:
|
|
||||||
if response.content:
|
if response.content:
|
||||||
return json.loads(response.content) if method == "post" else response.content
|
return json.loads(response.content) if method == "post" else response.content
|
||||||
else:
|
else:
|
||||||
return error_data
|
return error_data
|
||||||
except (requests.exceptions.Timeout, requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError) as e:
|
|
||||||
print e.message
|
|
||||||
return error_data
|
|
||||||
except socket.error as e:
|
|
||||||
print(e.message)
|
|
||||||
return error_data
|
|
||||||
else:
|
else:
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
except (requests.exceptions.Timeout, requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
|
||||||
|
pass
|
||||||
|
except socket.error:
|
||||||
|
pass
|
||||||
return error_data
|
return error_data
|
||||||
|
|
Loading…
Reference in New Issue