Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raulodev committed Dec 24, 2024
1 parent 0ed0f1e commit 194bb36
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 39 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ nauta = "nauta.cli:app"

[project]
name = "nauta"
version = "0.1.0"
version = "0.1.1"
authors = [{ name = "Raúl Cobiellas", email = "[email protected]" }]
description = "Línea de comandos para el nauta hogar Cuba"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions src/nauta/cli.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# pylint: disable=w0622
import typer
from nauta.commands.account import add, delete, list, default, password, info

from nauta.commands.account import add, default, delete, info, list, password
from nauta.commands.session import login, logout, time
from nauta.database import initialize_database


initialize_database()


Expand Down
65 changes: 35 additions & 30 deletions src/nauta/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import re
import typer

import requests
import typer
from bs4 import BeautifulSoup
from requests import ConnectionError, ReadTimeout
from nauta.constants import HOST_URL, LOGOUT_URL, AVAILABLE_TIME_URL
from nauta.database import add_session, get_session, delete_session

from nauta.constants import AVAILABLE_TIME_URL, HOST_URL, LOGOUT_URL
from nauta.database import add_session, delete_session, get_session


class NautaClient(object):
Expand Down Expand Up @@ -111,33 +113,37 @@ def logout(self, force=False):
)
return

available_time = self.available_time()
available_time = None

resp = requests.post(
LOGOUT_URL,
data={
"CSRFHW": session.csrfhw,
"username": session.username,
"ATTRIBUTE_UUID": session.attribute_uuid,
"wlanuserip": session.wlanuserip,
},
headers={"content-type": "application/x-www-form-urlencoded"},
timeout=60,
)
if not force:

if not resp.ok and not force:
typer.echo(typer.style(resp.reason, fg="red", bold=True))
return
available_time = self.available_time()

if "FAILURE" in resp.text.upper() and not force:
typer.echo(
typer.style("No se pudo cerrar la sesión", fg="red", bold=True)
resp = requests.post(
LOGOUT_URL,
data={
"CSRFHW": session.csrfhw,
"username": session.username,
"ATTRIBUTE_UUID": session.attribute_uuid,
"wlanuserip": session.wlanuserip,
},
headers={"content-type": "application/x-www-form-urlencoded"},
timeout=60,
)
return

if "SUCCESS" not in resp.text.upper() and not force:
typer.echo(typer.style(resp.text[:100], fg="red", bold=True))
return
if not resp.ok:
typer.echo(typer.style(resp.reason, fg="red", bold=True))
return

if "FAILURE" in resp.text.upper() and not force:
typer.echo(
typer.style("No se pudo cerrar la sesión", fg="red", bold=True)
)
return

if "SUCCESS" not in resp.text.upper() and not force:
typer.echo(typer.style(resp.text[:100], fg="red", bold=True))
return

delete_session()

Expand All @@ -150,11 +156,12 @@ def logout(self, force=False):
nl=force,
)

if available_time and not force:
if available_time:

typer.echo(
message=typer.style(
f": {available_time} tiempo restante", bold=True
f": {available_time} tiempo disponible para la próxima conexión",
bold=True,
),
)

Expand Down Expand Up @@ -202,7 +209,5 @@ def available_time(self) -> str:

except (ConnectionError, ReadTimeout):
typer.echo(
typer.style(
("No se pudo conectar con el servidor"), fg="red", bold=True
)
typer.style((" No se pudo obtener el tiempo"), fg="red", bold=True)
)
7 changes: 4 additions & 3 deletions src/nauta/commands/account.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import typer
from typing_extensions import Annotated

from nauta.database import (
list_account,
add_account,
delete_account,
get_account,
list_account,
update_account,
update_password,
get_account,
)
from nauta.secure import encrypt_password, decrypt_password, generate_key
from nauta.secure import decrypt_password, encrypt_password, generate_key


def add(
Expand Down
2 changes: 2 additions & 0 deletions src/nauta/commands/session.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Annotated

import typer

from nauta.client import NautaClient
from nauta.database import get_account
from nauta.secure import decrypt_password, generate_key
Expand Down
8 changes: 5 additions & 3 deletions src/nauta/database.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os
from typing import List
import sqlite3
import secrets
import sqlite3
from typing import List

from appdirs import user_data_dir

from nauta.constants import APP_AUTHOR, APP_NAME
from nauta.models import Account, Session
from nauta.constants import APP_NAME, APP_AUTHOR


def get_global_db_path():
Expand Down
1 change: 1 addition & 0 deletions src/nauta/secure.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
from hashlib import sha256

from nauta.database import get_secret


Expand Down

0 comments on commit 194bb36

Please sign in to comment.