修复打码错误
This commit is contained in:
2
main.py
2
main.py
@@ -10,7 +10,7 @@ from py12306.user.user import User
|
|||||||
def main():
|
def main():
|
||||||
# Thread(target=Query.run).start() # 余票查询
|
# Thread(target=Query.run).start() # 余票查询
|
||||||
create_thread_and_run(User, 'run', wait=False)
|
create_thread_and_run(User, 'run', wait=False)
|
||||||
Query.run()
|
# Query.run()
|
||||||
# Query.run()
|
# Query.run()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class OCR:
|
|||||||
"""
|
"""
|
||||||
self = cls()
|
self = cls()
|
||||||
return self.get_img_position_by_ruokuai(img_path)
|
return self.get_img_position_by_ruokuai(img_path)
|
||||||
pass
|
|
||||||
|
|
||||||
def get_img_position_by_ruokuai(self, img_path):
|
def get_img_position_by_ruokuai(self, img_path):
|
||||||
ruokuai_account = config.AUTO_CODE_ACCOUNT
|
ruokuai_account = config.AUTO_CODE_ACCOUNT
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class AuthCode:
|
|||||||
"""
|
"""
|
||||||
session = None
|
session = None
|
||||||
data_path = config.RUNTIME_DIR
|
data_path = config.RUNTIME_DIR
|
||||||
retry_time = 1
|
retry_time = 5
|
||||||
|
|
||||||
def __init__(self, session):
|
def __init__(self, session):
|
||||||
self.session = session
|
self.session = session
|
||||||
@@ -27,12 +27,19 @@ class AuthCode:
|
|||||||
self = cls(session)
|
self = cls(session)
|
||||||
img_path = self.download_code()
|
img_path = self.download_code()
|
||||||
position = OCR.get_img_position(img_path)
|
position = OCR.get_img_position(img_path)
|
||||||
|
if not position: # 打码失败
|
||||||
|
return self.retry_get_auth_code()
|
||||||
|
|
||||||
answer = ','.join(map(str, position))
|
answer = ','.join(map(str, position))
|
||||||
if not self.check_code(answer):
|
if not self.check_code(answer):
|
||||||
time.sleep(self.retry_time)
|
return self.retry_get_auth_code()
|
||||||
return self.get_auth_code(session)
|
|
||||||
return position
|
return position
|
||||||
|
|
||||||
|
def retry_get_auth_code(self): # TODO 安全次数检测
|
||||||
|
CommonLog.add_quick_log(CommonLog.MESSAGE_RETRY_AUTH_CODE.format(self.retry_time))
|
||||||
|
time.sleep(self.retry_time)
|
||||||
|
return self.get_auth_code(self.session)
|
||||||
|
|
||||||
def download_code(self):
|
def download_code(self):
|
||||||
url = API_AUTH_CODE_DOWNLOAD.get('url').format(random=random.random())
|
url = API_AUTH_CODE_DOWNLOAD.get('url').format(random=random.random())
|
||||||
code_path = self.data_path + 'code.png'
|
code_path = self.data_path + 'code.png'
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class BaseLog:
|
|||||||
if is_main_thread():
|
if is_main_thread():
|
||||||
logs = self.logs
|
logs = self.logs
|
||||||
else:
|
else:
|
||||||
logs = self.thread_logs[current_thread_id()]
|
logs = self.thread_logs.get(current_thread_id())
|
||||||
# for i in logs:
|
# for i in logs:
|
||||||
print(*logs, sep=sep, end=end, file=file)
|
print(*logs, sep=sep, end=end, file=file)
|
||||||
if self.quick_log:
|
if self.quick_log:
|
||||||
@@ -39,7 +39,7 @@ class BaseLog:
|
|||||||
if is_main_thread():
|
if is_main_thread():
|
||||||
self.logs = []
|
self.logs = []
|
||||||
else:
|
else:
|
||||||
del self.thread_logs[current_thread_id()]
|
if logs: del self.thread_logs[current_thread_id()]
|
||||||
# print(self.logs)
|
# print(self.logs)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from py12306.helpers.func import *
|
|||||||
@singleton
|
@singleton
|
||||||
class CommonLog(BaseLog):
|
class CommonLog(BaseLog):
|
||||||
MESSAGE_12306_IS_CLOSED = '当前时间: {} | 12306 休息时间,程序将在明天早上 6 点自动运行'
|
MESSAGE_12306_IS_CLOSED = '当前时间: {} | 12306 休息时间,程序将在明天早上 6 点自动运行'
|
||||||
|
MESSAGE_RETRY_AUTH_CODE = '{} 秒后重新获取验证码'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|||||||
Reference in New Issue
Block a user