Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix today entrust login #485

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions easytrader/grid_strategies.py
Original file line number Diff line number Diff line change
@@ -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")
7 changes: 5 additions & 2 deletions easytrader/universal_clienttrader.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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