Skip to content

Commit

Permalink
Merge pull request #4 from SuitETECSA/development
Browse files Browse the repository at this point in the history
Corregido errores
  • Loading branch information
lesclaz authored May 26, 2022
2 parents de1b9e1 + d438608 commit 938adec
Show file tree
Hide file tree
Showing 14 changed files with 1,944 additions and 20 deletions.
18 changes: 10 additions & 8 deletions PyLibSuitETECSA/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,32 +67,33 @@ def login(self, captcha_code: str):

return self

def recharge(self, recharge_code: str) -> None:
def recharge(self, recharge_code: str) -> bool:
"""
Recarga el saldo de la cuenta registrada.
:param recharge_code: Código de recarga.
:return:
"""
UserPortal.recharge(
is_confirmed = UserPortal.recharge(
self.session,
recharge_code
)

UserPortal.load_user_info(
self.session
)
return is_confirmed

def transfer(
self, mount_to_transfer: str,
account_to_transfer: str
) -> None:
) -> bool:
"""
Transfiere saldo a otra cuenta nauta.
:param mount_to_transfer: Monto a transferir.
:param account_to_transfer: Cuenta de destino.
:return:
"""
UserPortal.transfer(
is_confirmed = UserPortal.transfer(
self.session,
mount_to_transfer,
account_to_transfer,
Expand All @@ -102,26 +103,27 @@ def transfer(
UserPortal.load_user_info(
self.session
)
return is_confirmed

def change_password(self, new_passwrd: str) -> None:
def change_password(self, new_passwrd: str) -> bool:
"""
Cambia la contraseña de acceso a internet de la cuenta registrada.
:param new_passwrd: Nueva contraseña.
:return:
"""
UserPortal.change_password(
return UserPortal.change_password(
self.session,
self.password,
new_passwrd
)

def change_email_password(self, new_passwrd: str) -> None:
def change_email_password(self, new_passwrd: str) -> bool:
"""
Cambia la contraseña de la cuenta de correo asociada.
:param new_passwrd: Nueva contraseña.
:return:
"""
UserPortal.change_email_password(
return UserPortal.change_email_password(
self.session,
self.password,
new_passwrd
Expand Down
38 changes: 30 additions & 8 deletions PyLibSuitETECSA/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class UserPortal:
Action.LOGIN: f"{BASE_URL}user/login/es-es",
Action.LOAD_USER_INFO: f"{BASE_URL}useraaa/user_info",
Action.RECHARGE: f"{BASE_URL}useraaa/recharge_account",
Action.TRANSFER: f"{BASE_URL}useraaa/transfer_balance",
Action.CHANGE_PASSWORD: f"{BASE_URL}useraaa/change_password",
Action.CHANGE_EMAIL_PASSWORD: f"{BASE_URL}email/change_password",
Action.GET_CONNECTIONS: {
Expand Down Expand Up @@ -268,7 +269,7 @@ def load_user_info(cls, session: UserPortalSession) -> None:
)

@classmethod
def recharge(cls, session: UserPortalSession, recharge_code: str) -> None:
def recharge(cls, session: UserPortalSession, recharge_code: str) -> bool:
"""
Recarga la cuenta
Expand All @@ -284,13 +285,16 @@ def recharge(cls, session: UserPortalSession, recharge_code: str) -> None:
"recharge_code": recharge_code,
"btn_submit": ""
}
cls.__post_action(session, data, action)
response = cls.__post_action(session, data, action)
return cls.__is_confirmed(
bs4.BeautifulSoup(response.text, 'html.parser')
)

@classmethod
def transfer(
cls, session: UserPortalSession, mount_to_transfer: str,
account_to_transfer: str, password: str
) -> None:
) -> bool:
"""
Transfiere una cantidad de dinero de una cuenta a otra
Expand All @@ -312,13 +316,16 @@ def transfer(
"id_cuenta": account_to_transfer,
"action": "checkdata"
}
cls.__post_action(session, data, action)
response = cls.__post_action(session, data, action)
return cls.__is_confirmed(
bs4.BeautifulSoup(response.text, 'html.parser')
)

@classmethod
def change_password(
cls, session: UserPortalSession, old_password: str,
new_password: str
) -> None:
) -> bool:
"""
Cambia la contraseña del usuario
Expand All @@ -338,13 +345,16 @@ def change_password(
"repeat_new_password": new_password,
"btn_submit": ""
}
cls.__post_action(session, data, action)
response = cls.__post_action(session, data, action)
return cls.__is_confirmed(
bs4.BeautifulSoup(response.text, 'html.parser')
)

@classmethod
def change_email_password(
cls, session: UserPortalSession, old_password: str,
new_password: str
) -> None:
) -> bool:
"""
Cambia la contraseña de la cuenta de correo electrónico asociada con la
cuenta del usuario
Expand All @@ -366,7 +376,10 @@ def change_email_password(
"repeat_new_password": new_password,
"btn_submit": ""
}
cls.__post_action(session, data, action)
response = cls.__post_action(session, data, action)
return cls.__is_confirmed(
bs4.BeautifulSoup(response.text, 'html.parser')
)

@classmethod
def __post_action(
Expand Down Expand Up @@ -498,6 +511,15 @@ def __get_action(
trs.pop(0)
return trs

@classmethod
def __is_confirmed(cls, soup: bs4.BeautifulSoup):
script_text = soup.find_all("script")[-1].get_text().strip()
re_success = re.compile(r"toastr\.success\('(?P<reason>[^']*?)'\)")
match = re_success.match(script_text)
if match:
soup = bs4.BeautifulSoup(match.group("reason"), "html.parser")
return soup.find("li", {"class": "msg_message"}).text is not None

@classmethod
def get_connections(
cls, session: UserPortalSession, year: int, month: int
Expand Down
4 changes: 2 additions & 2 deletions buildDEB.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

app_name=PyLibSuitETECSA
app_version=0.1.3b1
module_name=libsuitetecsa
app_version=0.1.3b3
module_name=PyLibSuitETECSA

temp_dir=$app_name'_'$app_version'_all'
debian_dir="$temp_dir//DEBIAN"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_readme():

setup(
name='PyLibSuitETECSA',
version='0.1.3b2',
version='0.1.3b3',
packages=['PyLibSuitETECSA', 'PyLibSuitETECSA.core'],
url='https://github.com/SuitETECSA/PyLibSuitETECSA',
license='GNU General Public License v3',
Expand Down
Loading

0 comments on commit 938adec

Please sign in to comment.