feat: raise wrong credentials if login fails
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
__version__ = "0.1.1"
|
||||
__version__ = "0.1.2"
|
||||
|
||||
from .client import PPGEE
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
from . import PPGEE
|
||||
from ppgee import PPGEE
|
||||
import sys
|
||||
from . import errors
|
||||
|
||||
|
||||
def eprint(*args, **kwargs):
|
||||
print(*args, file=sys.stderr, **kwargs)
|
||||
|
||||
|
||||
def get_args():
|
||||
@@ -13,6 +19,7 @@ def get_args():
|
||||
async def cli():
|
||||
args = get_args()
|
||||
user, password = args.username, args.password
|
||||
try:
|
||||
async with PPGEE(user=user, password=password) as ppgee:
|
||||
frequency_page = await ppgee.frequency()
|
||||
await asyncio.sleep(1)
|
||||
@@ -20,11 +27,15 @@ async def cli():
|
||||
print("Attendency confirmed.")
|
||||
await frequency_page.confirm()
|
||||
else:
|
||||
print("Attendency not available yet.")
|
||||
eprint("Attendency not available yet.")
|
||||
await asyncio.sleep(1)
|
||||
except errors.InvalidCredentialsException:
|
||||
eprint("Invalid credentials.")
|
||||
|
||||
|
||||
def main():
|
||||
asyncio.run(cli())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -3,6 +3,7 @@ import logging
|
||||
from ppgee.http import HttpClient
|
||||
from ppgee.pages import FrequencyPage
|
||||
from functools import wraps
|
||||
from ppgee import errors
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -46,7 +47,10 @@ class PPGEE:
|
||||
async def login(self) -> None:
|
||||
logger.info("Logging in...")
|
||||
if self.user and self.password:
|
||||
await self.http.login(self.user, self.password)
|
||||
resp = await self.http.login(self.user, self.password)
|
||||
if "aindex" not in resp: # authentication failed
|
||||
await self.close()
|
||||
raise errors.InvalidCredentialsException()
|
||||
self.is_logged = True
|
||||
else:
|
||||
logger.info("Logged in without credentials")
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
class RequestException(Exception):
|
||||
...
|
||||
|
||||
|
||||
class InvalidCredentialsException(Exception):
|
||||
...
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "ppgee"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
description = ""
|
||||
authors = ["tiagovla <tiagovla@gmail.com>"]
|
||||
|
||||
|
||||
@@ -2,4 +2,4 @@ from ppgee import __version__
|
||||
|
||||
|
||||
def test_version():
|
||||
assert __version__ == "0.1.1"
|
||||
assert __version__ == "0.1.2"
|
||||
|
||||
Reference in New Issue
Block a user