-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 1,加入了针对 广发证券客户端的支持。 此客户端,为同花顺定制版本; 2,加入了 cancel_all_entrusts 函数,实现批量取消; 3,在_switch_left_menus/_switch_left_menus_by_shortcut中,加入了close_pop_windows函数,避免意外弹窗导致函数失败; 4,完善了edit空间输入字符串功能 * 1,完善readme * Revert "1,完善readme" This reverts commit ef64162
- Loading branch information
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- coding: utf-8 -*- | ||
import re | ||
import tempfile | ||
import time | ||
import os | ||
|
||
import pywinauto | ||
import pywinauto.clipboard | ||
|
||
from easytrader import clienttrader | ||
from easytrader.utils.captcha import recognize_verify_code | ||
|
||
|
||
class GFClientTrader(clienttrader.BaseLoginClientTrader): | ||
@property | ||
def broker_type(self): | ||
return "gf" | ||
|
||
def login(self, user, password, exe_path, comm_password=None, **kwargs): | ||
""" | ||
登陆客户端 | ||
:param user: 账号 | ||
:param password: 明文密码 | ||
:param exe_path: 客户端路径类似 'C:\\中国银河证券双子星3.2\\Binarystar.exe', | ||
默认 'C:\\中国银河证券双子星3.2\\Binarystar.exe' | ||
:param comm_password: 通讯密码, 华泰需要,可不设 | ||
:return: | ||
""" | ||
try: | ||
self._app = pywinauto.Application().connect( | ||
path=self._run_exe_path(exe_path), timeout=1 | ||
) | ||
# pylint: disable=broad-except | ||
except Exception: | ||
self._app = pywinauto.Application().start(exe_path) | ||
|
||
# wait login window ready | ||
while True: | ||
try: | ||
self._app.top_window().Edit1.wait("ready") | ||
break | ||
except RuntimeError: | ||
pass | ||
|
||
self.type_edit_control_keys(self._app.top_window().Edit1, user) | ||
self.type_edit_control_keys(self._app.top_window().Edit2, password) | ||
edit3 = self._app.top_window().window(control_id=0x3eb) | ||
while True: | ||
try: | ||
code = self._handle_verify_code() | ||
self.type_edit_control_keys(edit3, code) | ||
time.sleep(1) | ||
self._app.top_window()["登录(Y)"].click() | ||
# detect login is success or not | ||
try: | ||
self._app.top_window().wait_not("exists", 5) | ||
break | ||
|
||
# pylint: disable=broad-except | ||
except Exception: | ||
self._app.top_window()["确定"].click() | ||
|
||
# pylint: disable=broad-except | ||
except Exception: | ||
pass | ||
|
||
self._app = pywinauto.Application().connect( | ||
path=self._run_exe_path(exe_path), timeout=10 | ||
) | ||
self._main = self._app.window(title_re="""{title}.*""".format(title=self._config.TITLE)) | ||
self.close_pop_dialog() | ||
|
||
def _handle_verify_code(self): | ||
control = self._app.top_window().window(control_id=0x5db) | ||
control.click() | ||
time.sleep(0.2) | ||
file_path = tempfile.mktemp() + ".jpg" | ||
control.capture_as_image().save(file_path) | ||
time.sleep(0.2) | ||
vcode = recognize_verify_code(file_path, "gf_client") | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
return "".join(re.findall("[a-zA-Z0-9]+", vcode)) |
4bbe9fe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very useful🦄