Skip to content

Commit

Permalink
Bugfix: auto-login
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dh377 committed Jun 16, 2022
1 parent 0cdbfac commit 8bcaa8e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")

Expand All @@ -562,23 +562,32 @@ 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"
)
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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
23 changes: 13 additions & 10 deletions koapy/cli/utils/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions koapy/config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand All @@ -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
Expand Down

0 comments on commit 8bcaa8e

Please sign in to comment.