Skip to content

Commit

Permalink
Merge pull request #16 from fedebotu/actions/black
Browse files Browse the repository at this point in the history
Format Python code with psf/black push
  • Loading branch information
fedebotu authored Mar 7, 2024
2 parents 60ac74a + b82526c commit a1322aa
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions ktrains/korail/korail.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,27 +573,26 @@ def __init__(self, korail_id, korail_pw, auto_login=True, want_feedback=False):

def __enc_password(self, password):
url = KORAIL_CODE
data = {
'code': "app.login.cphd"
}
data = {"code": "app.login.cphd"}

r = self._session.post(url, data=data)
j = json.loads(r.text)

if j['strResult'] == 'SUCC' and j.get('app.login.cphd') is not None:
self._idx = j['app.login.cphd']['idx']
key = j['app.login.cphd']['key']
if j["strResult"] == "SUCC" and j.get("app.login.cphd") is not None:
self._idx = j["app.login.cphd"]["idx"]
key = j["app.login.cphd"]["key"]

encrypt_key = key.encode(encoding='utf-8', errors='strict')
iv = key[:16].encode(encoding='utf-8', errors='strict')
encrypt_key = key.encode(encoding="utf-8", errors="strict")
iv = key[:16].encode(encoding="utf-8", errors="strict")
cipher = AES.new(encrypt_key, AES.MODE_CBC, iv)

padded_data = pad(password.encode("utf-8"), AES.block_size)

return base64.b64encode(base64.b64encode(cipher.encrypt(padded_data))).decode("utf-8")
return base64.b64encode(
base64.b64encode(cipher.encrypt(padded_data))
).decode("utf-8")
else:
return False


def login(self, korail_id=None, korail_pw=None):
"""Login to Korail server.
Expand Down Expand Up @@ -649,8 +648,8 @@ def login(self, korail_id=None, korail_pw=None):
# 5 : for email,
"txtInputFlg": txt_input_flg,
"txtMemberNo": korail_id,
'txtPwd': self.__enc_password(korail_pw),
'idx': self._idx
"txtPwd": self.__enc_password(korail_pw),
"idx": self._idx,
}

r = self._session.post(url, data=data)
Expand Down

0 comments on commit a1322aa

Please sign in to comment.