From 7f32d434879ade940fd75c3c1b6b9e8938c7dc8f Mon Sep 17 00:00:00 2001 From: Yosef Lin Date: Thu, 18 May 2023 15:18:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E6=97=A0=E6=B3=95=E8=8E=B7=E5=8F=96=E6=8C=81?= =?UTF-8?q?=E4=BB=93=E7=AD=89=E4=BF=A1=E6=81=AF=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9B=20=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- easytrader/grid_strategies.py | 49 ++++++++++++++++++++++++---- easytrader/universal_clienttrader.py | 7 ++-- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/easytrader/grid_strategies.py b/easytrader/grid_strategies.py index b294b967..8ead0ff6 100644 --- a/easytrader/grid_strategies.py +++ b/easytrader/grid_strategies.py @@ -181,12 +181,47 @@ def get(self, control_id: int) -> List[Dict]: # ctrl+s 保存 grid 内容为 xls 文件 self._set_foreground(grid) # setFocus buggy, instead of SetForegroundWindow grid.type_keys("^s", set_foreground=False) - count = 10 - while count > 0: - if self._trader.is_exist_pop_dialog(): - break - self._trader.wait(0.2) - count -= 1 + # count = 10 + # while count > 0: + # if self._trader.is_exist_pop_dialog(): + # break + # self._trader.wait(0.2) + # count -= 1 + + if (self._trader.app.top_window().window(class_name="Static", title_re="验证码").exists(timeout=1)): #检查是否有验证码输入Window + file_path = "tmp.png" + count = 5 + found = False + while count > 0: + self._trader.app.top_window().window( + control_id=0x965, class_name="Static" + ).capture_as_image().save( + file_path + ) # 保存验证码 + + captcha_num = captcha_recognize(file_path).strip() # 识别验证码 + captcha_num = "".join(captcha_num.split()) + logger.info("captcha result-->" + captcha_num) + if len(captcha_num) == 4: + + editor = self._trader.app.top_window().window( + control_id=0x964, class_name="Edit") + editor.select() + editor.type_keys(captcha_num) + + self._trader.app.top_window().set_focus() + pywinauto.keyboard.SendKeys("{ENTER}") # 模拟发送enter,点击确定 + if self._trader.app.window(title='另存为').exists(timeout=1): + found = True + break + logger.info(f"captcha result:{captcha_num} error") + count -= 1 + self._trader.wait(0.1) + self._trader.app.top_window().window( + control_id=0x965, class_name="Static" + ).click() + if not found: + self._trader.app.top_window().Button2.click() # 点击取消 temp_path = tempfile.mktemp(suffix=".xls", dir=self.tmp_folder) self._set_foreground(self._trader.app.top_window()) @@ -213,4 +248,4 @@ def _format_grid_data(self, data: str) -> List[Dict]: dtype=self._trader.config.GRID_DTYPE, na_filter=False, ) - return df.to_dict("records") + return df.to_dict("records") \ No newline at end of file diff --git a/easytrader/universal_clienttrader.py b/easytrader/universal_clienttrader.py index afec1eae..d72c4e09 100644 --- a/easytrader/universal_clienttrader.py +++ b/easytrader/universal_clienttrader.py @@ -44,8 +44,11 @@ def login(self, user, password, exe_path, comm_password=None, **kwargs): self.wait(1) self._app.window(handle=login_window).Edit1.set_focus() self._app.window(handle=login_window).Edit1.type_keys(user) - - self._app.window(handle=login_window).button7.click() + self.wait(1) + self._app.window(handle=login_window).Edit2.set_focus() + self._app.window(handle=login_window).Edit2.type_keys(password) + self.wait(1) + self._app.window(handle=login_window).button4.click() # detect login is success or not # self._app.top_window().wait_not("exists", 100) From 741eebca254c5e48891f37ae737d118929e1485d Mon Sep 17 00:00:00 2001 From: Yosef Lin Date: Thu, 18 May 2023 15:21:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=BF=98=E4=BA=86=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index a101ca4f..46c564e8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -28,4 +28,4 @@ requests==2.19.1 six==1.11.0 urllib3==1.23; python_version != '3.1.*' werkzeug==0.14.1 - +pytesseract==0.3.10