From bc29d8a8aa997066a5e743361e6654980a8d1481 Mon Sep 17 00:00:00 2001 From: Jalin Date: Tue, 8 Jan 2019 19:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BE=93=E5=87=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ py12306/helpers/OCR.py | 40 +++++++++++----------------------------- py12306/user/job.py | 16 +++++++++------- 3 files changed, 22 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index cf18fc8..288ff8d 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,10 @@ - [x] 电话语音通知 - [x] 多账号、多任务、多线程支持 - [x] 单个任务多站点查询 +- [ ] 分布式运行 - [ ] Docker 支持 - [ ] 邮件通知 +- [ ] Web 管理页面 ## 使用 py12306 需要运行在 python 3.6 以上版本(其它版本暂未测试) diff --git a/py12306/helpers/OCR.py b/py12306/helpers/OCR.py index 1e10b21..862da08 100644 --- a/py12306/helpers/OCR.py +++ b/py12306/helpers/OCR.py @@ -1,3 +1,6 @@ +import math +import random + from py12306 import config from py12306.log.common_log import CommonLog from py12306.vender.ruokuai.main import RKClient @@ -32,39 +35,18 @@ class OCR: def get_image_position_by_offset(self, offsets): positions = [] + width = 70 + height = 70 + random_num = random.randint(0, 10) for offset in offsets: - if offset == '1': - y = 46 - x = 42 - elif offset == '2': - y = 46 - x = 105 - elif offset == '3': - y = 45 - x = 184 - elif offset == '4': - y = 48 - x = 256 - elif offset == '5': - y = 36 - x = 117 - elif offset == '6': - y = 112 - x = 115 - elif offset == '7': - y = 114 - x = 181 - elif offset == '8': - y = 111 - x = 252 - else: - pass - positions.append(x) - positions.append(y) + offset = int(offset) + x = width * (offset % 5) - width / 2 + random_num + y = height * math.ceil(offset / 4) - height / 2 - random_num + positions.append(int(x)) + positions.append(int(y)) return positions - if __name__ == '__main__': pass # code_result = AuthCode.get_auth_code() diff --git a/py12306/user/job.py b/py12306/user/job.py index 31cc40c..fcbb4b6 100644 --- a/py12306/user/job.py +++ b/py12306/user/job.py @@ -103,10 +103,10 @@ class UserJob: elif result.get('result_code') == 2: # 账号之内错误 # 登录失败,用户名或密码为空 # 密码输入错误 - UserLog.add_quick_log(UserLog.MESSAGE_LOGIN_FAIL.format(result.get('result_message'))) + UserLog.add_quick_log(UserLog.MESSAGE_LOGIN_FAIL.format(result.get('result_message'))).flush() else: UserLog.add_quick_log( - UserLog.MESSAGE_LOGIN_FAIL.format(result.get('result_message', result.get('message', '-')))) + UserLog.MESSAGE_LOGIN_FAIL.format(result.get('result_message', result.get('message', '-')))).flush() return False @@ -117,6 +117,9 @@ class UserJob: is_login = response.json().get('data').get('flag', False) if is_login: self.save_user() + self.get_user_info() # 检测应该是不会维持状态,这里再请求下个人中心看有没有有 + + return is_login def auth_uamtk(self): @@ -168,12 +171,11 @@ class UserJob: :return: """ UserLog.add_quick_log(UserLog.MESSAGE_LOADED_USER.format(self.user_name)) - if self.check_user_is_login(): - UserLog.add_quick_log(UserLog.MESSAGE_LOADED_USER_SUCCESS.format(self.user_name)) - self.get_user_info() + if self.check_user_is_login() and self.get_user_info(): + UserLog.add_quick_log(UserLog.MESSAGE_LOADED_USER_SUCCESS.format(self.user_name)).flush() UserLog.print_welcome_user(self) else: - UserLog.add_quick_log(UserLog.MESSAGE_LOADED_USER_BUT_EXPIRED) + UserLog.add_quick_log(UserLog.MESSAGE_LOADED_USER_BUT_EXPIRED).flush() def get_user_info(self): response = self.session.get(API_USER_INFO.get('url')) @@ -205,7 +207,7 @@ class UserJob: return self.passengers else: UserLog.add_quick_log( - UserLog.MESSAGE_GET_USER_PASSENGERS_FAIL.format(result.get('messages', '-'), self.retry_time)) + UserLog.MESSAGE_GET_USER_PASSENGERS_FAIL.format(result.get('messages', '-'), self.retry_time)).flush() stay_second(self.retry_time) return self.get_user_passengers()