From 8bcaa8ef535bd6616a877a26fdd2a49ffb0d3514 Mon Sep 17 00:00:00 2001 From: Dongyoon Han <5795942+dh377@users.noreply.github.com> Date: Fri, 17 Jun 2022 05:34:27 +0900 Subject: [PATCH] Bugfix: auto-login 1. simulation server checkbox cannot be set with pywinauto's mouse click emulation. 2. In case of trying to set account passwords partially, KOAPY try to set password with global password (0000) anyway, auto-login failed to set because of errors (account password does not match). --- .../core/KiwoomOpenApiPlusQAxWidgetMixin.py | 46 +++++++++++-------- koapy/cli/utils/credentials.py | 23 ++++++---- koapy/config.conf | 8 +--- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/koapy/backend/kiwoom_open_api_plus/core/KiwoomOpenApiPlusQAxWidgetMixin.py b/koapy/backend/kiwoom_open_api_plus/core/KiwoomOpenApiPlusQAxWidgetMixin.py index 48e8a1fd..e43a9d84 100644 --- a/koapy/backend/kiwoom_open_api_plus/core/KiwoomOpenApiPlusQAxWidgetMixin.py +++ b/koapy/backend/kiwoom_open_api_plus/core/KiwoomOpenApiPlusQAxWidgetMixin.py @@ -509,7 +509,7 @@ def LoginUsingPywinauto_Impl(cls, credentials: Optional[Mapping[str, Any]] = Non credentials = config.get("koapy.backend.kiwoom_open_api_plus.credentials") is_in_development = False - use_set_text = False + emulate_keyboard_input = True userid = credentials.get("user_id") password = credentials.get("user_password") @@ -535,20 +535,20 @@ def LoginUsingPywinauto_Impl(cls, credentials: Optional[Mapping[str, Any]] = Non if userid: cls.logger.info("Putting userid") - if use_set_text: - login_window["Edit1"].set_text(userid) - else: + if emulate_keyboard_input: login_window["Edit1"].set_focus() pywinauto.keyboard.send_keys(userid) pywinauto.keyboard.send_keys("{TAB}") + else: + login_window["Edit1"].set_text(userid) if password: cls.logger.info("Putting password") - if use_set_text: - login_window["Edit2"].set_text(password) - else: + if emulate_keyboard_input: login_window["Edit2"].set_focus() pywinauto.keyboard.send_keys(password) pywinauto.keyboard.send_keys("{TAB}") + else: + login_window["Edit2"].set_text(password) else: raise RuntimeError("'user_password' not set, please check credentials") @@ -562,15 +562,20 @@ def LoginUsingPywinauto_Impl(cls, credentials: Optional[Mapping[str, Any]] = Non if not is_simulation: if not login_window["Edit3"].is_enabled(): cls.logger.info("Unchecking to use simulation server") - login_window["Button5"].uncheck_by_click() + if emulate_keyboard_input: + login_window["Button5"].set_focus() + pywinauto.keyboard.send_keys("{SPACE}") + else: + login_window["Button5"].uncheck_by_click() + if cert: cls.logger.info("Putting cert password") - if use_set_text: - login_window["Edit3"].set_text(cert) - else: + if emulate_keyboard_input: login_window["Edit3"].set_focus() pywinauto.keyboard.send_keys(cert) pywinauto.keyboard.send_keys("{TAB}") + else: + login_window["Edit3"].set_text(cert) else: raise RuntimeError( "'cert_password' not set, please check credentials" @@ -578,7 +583,11 @@ def LoginUsingPywinauto_Impl(cls, credentials: Optional[Mapping[str, Any]] = Non else: if login_window["Edit3"].is_enabled(): cls.logger.info("Checking to use simulation server") - login_window["Button5"].check_by_click() + if emulate_keyboard_input: + login_window["Button5"].set_focus() + pywinauto.keyboard.send_keys("{SPACE}") + else: + login_window["Button5"].check_by_click() cls.logger.info("Logging in") login_window["Button1"].click() @@ -807,7 +816,8 @@ def EnableAutoLoginUsingPywinauto_Impl( if account_passwords is None: credentials = config.get("koapy.backend.kiwoom_open_api_plus.credentials") account_passwords = credentials.get("account_passwords") - + account_passwords = dict(account_passwords) + is_in_development = False desktop = pywinauto.Desktop(allow_magic_lookup=False) @@ -835,12 +845,10 @@ def EnableAutoLoginUsingPywinauto_Impl( for i in range(account_cnt): account_combo.select(i) account_no = account_combo.selected_text().split()[0] - if account_no in account_passwords: - account_window["Edit"].set_text(account_passwords[account_no]) - elif "0000000000" in account_passwords: - account_window["Edit"].set_text(account_passwords["0000000000"]) - account_window["등록"].click() - + if account_pw := account_passwords.get(account_no) or account_passwords.get("0000000000"): + account_window["Edit"].set_text(account_pw) + account_window["등록"].click() + cls.logger.info("Closing account window") account_window["닫기"].click() diff --git a/koapy/cli/utils/credentials.py b/koapy/cli/utils/credentials.py index e26b1504..8df613a3 100644 --- a/koapy/cli/utils/credentials.py +++ b/koapy/cli/utils/credentials.py @@ -43,17 +43,20 @@ def prompt_credentials(): default=default_cert_password, show_default=False, ) - account_count = click.prompt("Account Count", type=int, default=1) + account_passwords = {} - for _ in range(account_count): - account_number = click.prompt("Account Number", default="0000000000") - account_password = click.prompt( - "Account Password", - hide_input=True, - default="0000", - show_default=False, - ) - account_passwords[account_number] = account_password + if is_simulation: + account_passwords['0000000000'] = '0000' + else: + account_count = click.prompt("Account Count", type=int, default=1) + for _ in range(account_count): + account_number = click.prompt("Account Number", default="0000000000") + account_password = click.prompt( + "Account Password", + hide_input=True, + show_default=False, + ) + account_passwords[account_number] = account_password credentials = { "user_id": user_id, diff --git a/koapy/config.conf b/koapy/config.conf index 367895db..3ca79132 100644 --- a/koapy/config.conf +++ b/koapy/config.conf @@ -38,9 +38,7 @@ user_password = "" cert_password = "" is_simulation = true - account_passwords { - 0000000000 = "0000" - } + account_passwords {} } koapy.backend.daishin_cybos_plus.credentials { user_id = "" @@ -49,9 +47,7 @@ auto_account_password = true auto_cert_password = true price_check_only = true - account_passwords { - 000000000 = "0000" - } + account_passwords {} } koapy.utils.logging.config { version = 1