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