Skip to content

Commit

Permalink
Merge pull request #3 from SuitETECSA/development
Browse files Browse the repository at this point in the history
Actualización
  • Loading branch information
lesclaz authored May 21, 2022
2 parents 33b6f27 + 7e38a5b commit de1b9e1
Show file tree
Hide file tree
Showing 28 changed files with 3,971 additions and 1,007 deletions.
File renamed without changes.
5 changes: 0 additions & 5 deletions libsuitetecsa/__init__.py → PyLibSuitETECSA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@
# #
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os

appdata_path = os.path.expanduser("~/.local/share/libsuitetecsa")
os.makedirs(appdata_path, exist_ok=True)
59 changes: 14 additions & 45 deletions libsuitetecsa/api.py → PyLibSuitETECSA/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

from requests import RequestException

from libsuitetecsa.__about__ import __name__ as prog_name
from libsuitetecsa.core.exception import LogoutException
from libsuitetecsa.core.models import Connection, Recharge, Transfer, QuotePaid
from libsuitetecsa.core.protocol import Nauta, UserPortal
from libsuitetecsa.core.session import NautaSession
from PyLibSuitETECSA.core.exception import LogoutException
from PyLibSuitETECSA.core.models import Connection, Recharge, Transfer, \
QuotePaid
from PyLibSuitETECSA.core.protocol import UserPortal, Nauta
from PyLibSuitETECSA.core.session import NautaSession
from PyLibSuitETECSA.core.utils import Action


class UserPortalClient:
Expand All @@ -36,7 +37,6 @@ def init_session(self) -> None:
:return:
"""
self.session = UserPortal.create_session()
self.session.save()

@property
def captcha_as_bytes(self) -> bytes:
Expand Down Expand Up @@ -65,8 +65,6 @@ def login(self, captcha_code: str):
captcha_code
)

self.session.save()

return self

def recharge(self, recharge_code: str) -> None:
Expand All @@ -84,8 +82,6 @@ def recharge(self, recharge_code: str) -> None:
self.session
)

self.session.save()

def transfer(
self, mount_to_transfer: str,
account_to_transfer: str
Expand All @@ -107,8 +103,6 @@ def transfer(
self.session
)

self.session.save()

def change_password(self, new_passwrd: str) -> None:
"""
Cambia la contraseña de acceso a internet de la cuenta registrada.
Expand All @@ -134,7 +128,7 @@ def change_email_password(self, new_passwrd: str) -> None:
)

def get_lasts(
self, action: str = UserPortal.ACTION_CONNECTIONS,
self, action: str = Action.GET_CONNECTIONS,
large: int = 5
) -> List[Any]:
"""
Expand Down Expand Up @@ -377,14 +371,6 @@ def init_session(self):
:return:
"""
self.session = Nauta.create_session()
self.session.save()

@property
def is_logged_in(self):
"""
:return: True si hay una sesión abierta.
"""
return NautaSession.is_logged_in()

def login(self):
"""
Expand All @@ -400,8 +386,6 @@ def login(self):
self.password
)

self.session.save()

return self

@property
Expand Down Expand Up @@ -430,20 +414,13 @@ def remaining_time(self):
"""
:return: Tiempo disponible de la cuenta registrada.
"""
dispose_session = False
try:
if not self.session:
dispose_session = True
self.session = NautaSession()
if not self.session:
self.session = NautaSession()

return Nauta.get_user_time(
session=self.session,
username=self.user,
)
finally:
if self.session and dispose_session:
self.session.dispose()
self.session = None
return Nauta.get_user_time(
session=self.session,
username=self.user,
)

def logout(self):
"""
Expand All @@ -462,17 +439,9 @@ def logout(self):
except RequestException:
raise LogoutException(
"Hay problemas en la red y no se puede cerrar la session.\n"
"Es posible que ya este desconectado. Intente con '{} down' "
"dentro de unos minutos".format(prog_name)
"Es posible que ya este desconectado."
)

def load_last_session(self):
"""
Carga la última sesión.
:return:
"""
self.session = NautaSession.load()

def __enter__(self):
pass

Expand Down
22 changes: 0 additions & 22 deletions libsuitetecsa/__about__.py → PyLibSuitETECSA/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,3 @@
# #
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__all__ = [
"__name__",
"__author__",
"__email__",
"__version__",
"__url__",
"__description__",
"__keywords__",
"__license__",
]

__name__ = "libsuitetecsa"
__version__ = "0.1.3-BETA1"
__keywords__ = "ETECSA nauta tools"
__license__ = "GNU GPLv3"

__author__ = "Lesly Cintra Laza"
__email__ = "lesclaz95@gmail.com"
__url__ = "https://github.com/marilasoft/PyLibSuitETECSA"

__description__ = "Python API para los servicios de ETECSA"
File renamed without changes.
65 changes: 23 additions & 42 deletions libsuitetecsa/core/models.py → PyLibSuitETECSA/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@
from datetime import datetime


class Connection(object):
class ActionObject:

@staticmethod
def __text_to_datetime(text: str) -> datetime:
date_, time_ = text.split(" ")
day, month, year = date_.split("/")
hours, minutes, seconds = time_.split(":")
return datetime(int(year), int(month), int(day),
int(hours), int(minutes), int(seconds))


class Connection(ActionObject):

def __init__(self, **kwargs):
self.start_session = None
Expand All @@ -30,22 +41,15 @@ def __init__(self, **kwargs):
@property
def start_session_as_dt(self):
if self.start_session:
date_ = self.start_session.split(" ")[0]
time_ = self.start_session.split(" ")[1]
return self.__text_to_datetime(self.start_session)

day = date_.split("/")[0]
month = date_.split("/")[1]
year = date_.split("/")[2]

hours = time_.split(":")[0]
minutes = time_.split(":")[1]
seconds = time_.split(":")[2]

return datetime(int(year), int(month), int(day),
int(hours), int(minutes), int(seconds))
@property
def end_session_as_dt(self):
if self.end_session:
return self.__text_to_datetime(self.end_session)


class Recharge(object):
class Recharge(ActionObject):

def __init__(self, **kwargs):
self.date = None
Expand All @@ -56,19 +60,8 @@ def __init__(self, **kwargs):

@property
def date_as_dt(self):
date_ = self.date.split(" ")[0]
time_ = self.date.split(" ")[1]

day = date_.split("/")[0]
month = date_.split("/")[1]
year = date_.split("/")[2]

hours = time_.split(":")[0]
minutes = time_.split(":")[1]
seconds = time_.split(":")[2]

return datetime(int(year), int(month), int(day),
int(hours), int(minutes), int(seconds))
if self.date:
return self.__text_to_datetime(self.date)


class QuotePaid(Recharge):
Expand All @@ -79,29 +72,17 @@ def __init__(self, **kwargs):
self.__dict__.update(kwargs)


class Transfer(object):
class Transfer(ActionObject):

def __init__(self, **kwargs):
self.date = None
self.import_ = None
self.destiny_account = None
self.__dict__.update(kwargs)

@property
def date_as_dt(self):
date_ = self.date.split(" ")[0]
time_ = self.date.split(" ")[1]

day = date_.split("/")[0]
month = date_.split("/")[1]
year = date_.split("/")[2]

hours = time_.split(":")[0]
minutes = time_.split(":")[1]
seconds = time_.split(":")[2]

return datetime(int(year), int(month), int(day),
int(hours), int(minutes), int(seconds))
if self.date:
return self.__text_to_datetime(self.date)


class User:
Expand Down
Loading

0 comments on commit de1b9e1

Please sign in to comment.