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