From 017ea4f354d840f1122f989099c7a7d12c3bf23c Mon Sep 17 00:00:00 2001 From: tiagovla Date: Tue, 4 Oct 2022 02:14:44 -0300 Subject: [PATCH] feat: add cli script --- ppgee/__init__.py | 2 +- ppgee/__main__.py | 30 ++++++++++++++++++++++++++++++ ppgee/client.py | 1 - pyproject.toml | 5 ++++- tests/test_ppgee.py | 2 +- 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 ppgee/__main__.py diff --git a/ppgee/__init__.py b/ppgee/__init__.py index 2f17a0e..518ed23 100644 --- a/ppgee/__init__.py +++ b/ppgee/__init__.py @@ -1,3 +1,3 @@ -__version__ = "0.1.0" +__version__ = "0.1.1" from .client import PPGEE diff --git a/ppgee/__main__.py b/ppgee/__main__.py new file mode 100644 index 0000000..766a7b0 --- /dev/null +++ b/ppgee/__main__.py @@ -0,0 +1,30 @@ +import argparse +import asyncio +from . import PPGEE + + +def get_args(): + parser = argparse.ArgumentParser(description="Confirm your montly PPGEE attendency") + parser.add_argument("username", type=str, help="Your PPGEE's username") + parser.add_argument("password", type=str, help="Your PPGEE's password") + return parser.parse_args() + + +async def cli(): + args = get_args() + user, password = args.username, args.password + async with PPGEE(user=user, password=password) as ppgee: + frequency_page = await ppgee.frequency() + await asyncio.sleep(1) + if frequency_page.is_available(): + print("Attendency confirmed.") + await frequency_page.confirm() + else: + print("Attendency not available yet.") + await asyncio.sleep(1) + +def main(): + asyncio.run(cli()) + +if __name__ == "__main__": + main() diff --git a/ppgee/client.py b/ppgee/client.py index 4bf43f7..fe4b11d 100644 --- a/ppgee/client.py +++ b/ppgee/client.py @@ -10,7 +10,6 @@ logger = logging.getLogger(__name__) def is_logged_check(method): @wraps(method) def wrapper(self, *args, **kwargs): - print("checking if logged in", self.is_logged) if not self.is_logged: raise Exception("You must be logged in to use this method") return method(self, *args, **kwargs) diff --git a/pyproject.toml b/pyproject.toml index e64acc5..e431e52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ppgee" -version = "0.1.0" +version = "0.1.1" description = "" authors = ["tiagovla "] @@ -13,6 +13,9 @@ beautifulsoup4 = "^4.11.1" pytest = "^5.2" sendgrid = "^6.9.7" +[tool.poetry.scripts] +ppgee = "ppgee.__main__:main" + [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" diff --git a/tests/test_ppgee.py b/tests/test_ppgee.py index 0cf6d2f..c0b03da 100644 --- a/tests/test_ppgee.py +++ b/tests/test_ppgee.py @@ -2,4 +2,4 @@ from ppgee import __version__ def test_version(): - assert __version__ == '0.1.0' + assert __version__ == "0.1.1"