chore: initial logic

This commit is contained in:
2022-09-16 19:19:12 -03:00
commit 693e92c789
9 changed files with 346 additions and 0 deletions

0
README.rst Normal file
View File

18
demo/check_frequency.py Normal file
View File

@@ -0,0 +1,18 @@
import asyncio
import logging
logging.basicConfig(level=logging.DEBUG)
from ppgee import PPGEE
async def main():
cpf = "00011122233"
async with PPGEE(cpf, cpf) as ppgee:
response = await ppgee.frequency()
if "Opção não disponível" in response:
print("Not ready yet")
await asyncio.sleep(5)
if __name__ == "__main__":
asyncio.run(main())

250
poetry.lock generated Normal file
View File

@@ -0,0 +1,250 @@
[[package]]
name = "aiohttp"
version = "3.8.1"
description = "Async http client/server framework (asyncio)"
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
aiosignal = ">=1.1.2"
async-timeout = ">=4.0.0a3,<5.0"
attrs = ">=17.3.0"
charset-normalizer = ">=2.0,<3.0"
frozenlist = ">=1.1.1"
multidict = ">=4.5,<7.0"
yarl = ">=1.0,<2.0"
[package.extras]
speedups = ["aiodns", "brotli", "cchardet"]
[[package]]
name = "aiosignal"
version = "1.2.0"
description = "aiosignal: a list of registered asynchronous callbacks"
category = "main"
optional = false
python-versions = ">=3.6"
[package.dependencies]
frozenlist = ">=1.1.0"
[[package]]
name = "async-timeout"
version = "4.0.2"
description = "Timeout context manager for asyncio programs"
category = "main"
optional = false
python-versions = ">=3.6"
[[package]]
name = "atomicwrites"
version = "1.4.1"
description = "Atomic file writes."
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "attrs"
version = "22.1.0"
description = "Classes Without Boilerplate"
category = "main"
optional = false
python-versions = ">=3.5"
[package.extras]
dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"]
docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"]
tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "zope.interface", "cloudpickle"]
tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "mypy (>=0.900,!=0.940)", "pytest-mypy-plugins", "cloudpickle"]
[[package]]
name = "charset-normalizer"
version = "2.1.1"
description = "The Real First Universal Charset Detector. Open, modern and actively maintained alternative to Chardet."
category = "main"
optional = false
python-versions = ">=3.6.0"
[package.extras]
unicode_backport = ["unicodedata2"]
[[package]]
name = "colorama"
version = "0.4.5"
description = "Cross-platform colored terminal text."
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[[package]]
name = "frozenlist"
version = "1.3.1"
description = "A list-like structure which implements collections.abc.MutableSequence"
category = "main"
optional = false
python-versions = ">=3.7"
[[package]]
name = "idna"
version = "3.4"
description = "Internationalized Domain Names in Applications (IDNA)"
category = "main"
optional = false
python-versions = ">=3.5"
[[package]]
name = "more-itertools"
version = "8.14.0"
description = "More routines for operating on iterables, beyond itertools"
category = "dev"
optional = false
python-versions = ">=3.5"
[[package]]
name = "multidict"
version = "6.0.2"
description = "multidict implementation"
category = "main"
optional = false
python-versions = ">=3.7"
[[package]]
name = "packaging"
version = "21.3"
description = "Core utilities for Python packages"
category = "dev"
optional = false
python-versions = ">=3.6"
[package.dependencies]
pyparsing = ">=2.0.2,<3.0.5 || >3.0.5"
[[package]]
name = "pluggy"
version = "0.13.1"
description = "plugin and hook calling mechanisms for python"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[package.extras]
dev = ["pre-commit", "tox"]
[[package]]
name = "py"
version = "1.11.0"
description = "library with cross-python path, ini-parsing, io, code, log facilities"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[[package]]
name = "pyparsing"
version = "3.0.9"
description = "pyparsing module - Classes and methods to define and execute parsing grammars"
category = "dev"
optional = false
python-versions = ">=3.6.8"
[package.extras]
diagrams = ["railroad-diagrams", "jinja2"]
[[package]]
name = "pytest"
version = "5.4.3"
description = "pytest: simple powerful testing with Python"
category = "dev"
optional = false
python-versions = ">=3.5"
[package.dependencies]
atomicwrites = {version = ">=1.0", markers = "sys_platform == \"win32\""}
attrs = ">=17.4.0"
colorama = {version = "*", markers = "sys_platform == \"win32\""}
more-itertools = ">=4.0.0"
packaging = "*"
pluggy = ">=0.12,<1.0"
py = ">=1.5.0"
wcwidth = "*"
[package.extras]
checkqa-mypy = ["mypy (==v0.761)"]
testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"]
[[package]]
name = "python-http-client"
version = "3.3.7"
description = "HTTP REST client, simplified for Python"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
[[package]]
name = "sendgrid"
version = "6.9.7"
description = "Twilio SendGrid library for Python"
category = "dev"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[package.dependencies]
python-http-client = ">=3.2.1"
starkbank-ecdsa = ">=2.0.1"
[[package]]
name = "starkbank-ecdsa"
version = "2.0.3"
description = "A lightweight and fast pure python ECDSA library"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "wcwidth"
version = "0.2.5"
description = "Measures the displayed width of unicode strings in a terminal"
category = "dev"
optional = false
python-versions = "*"
[[package]]
name = "yarl"
version = "1.8.1"
description = "Yet another URL library"
category = "main"
optional = false
python-versions = ">=3.7"
[package.dependencies]
idna = ">=2.0"
multidict = ">=4.0"
[metadata]
lock-version = "1.1"
python-versions = "^3.10"
content-hash = "e2c81cf40eb115ecc3c2e19723d94097e237dbda967e5eaf06660c758e73e915"
[metadata.files]
aiohttp = []
aiosignal = []
async-timeout = []
atomicwrites = []
attrs = []
charset-normalizer = []
colorama = []
frozenlist = []
idna = []
more-itertools = []
multidict = []
packaging = []
pluggy = []
py = []
pyparsing = []
pytest = []
python-http-client = []
sendgrid = []
starkbank-ecdsa = []
wcwidth = []
yarl = []

3
ppgee/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
__version__ = "0.1.0"
from .client import PPGEE

51
ppgee/client.py Normal file
View File

@@ -0,0 +1,51 @@
import aiohttp
import asyncio
import logging
from ppgee.errors import RequestException
logger = logging.getLogger(__name__)
class PPGEE:
def __init__(self, user: str, password: str) -> None:
self.user = user
self.password = password
self.session: aiohttp.ClientSession
async def __aenter__(self):
self.session = aiohttp.ClientSession()
await self.login()
return self
async def _request(self, method: str, url: str, **kwargs) -> str:
async with self.session.request(method, url, **kwargs) as resp:
if resp.status != 200:
raise RequestException(
f"Request to url {url} with method {method} failed with status code {resp.status}."
)
return await resp.text()
async def login(self) -> str:
logger.debug("Sending request to login.")
data = {"login": self.user, "senha": self.password}
return await self._request(
"post", "https://www.ppgee.ufmg.br/ppgeenet/login.php", data=data
)
async def frequency(self) -> str:
logger.debug("Sending request to frequency.")
return await self._request(
"get", "https://www.ppgee.ufmg.br/ppgeenet/afreq.php"
)
async def logoff(self) -> str:
logger.debug("Sending request to logoff.")
return await self._request(
"get", "https://www.ppgee.ufmg.br/ppgeenet/logoff.php"
)
async def __aexit__(self, exc_type, exc, tb) -> None:
await self.logoff()
await asyncio.sleep(1)
if self.session:
await self.session.close()

2
ppgee/errors.py Normal file
View File

@@ -0,0 +1,2 @@
class RequestException(Exception):
...

17
pyproject.toml Normal file
View File

@@ -0,0 +1,17 @@
[tool.poetry]
name = "ppgee"
version = "0.1.0"
description = ""
authors = ["tiagovla <tiagovla@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.10"
aiohttp = "^3.8.1"
[tool.poetry.dev-dependencies]
pytest = "^5.2"
sendgrid = "^6.9.7"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

0
tests/__init__.py Normal file
View File

5
tests/test_ppgee.py Normal file
View File

@@ -0,0 +1,5 @@
from ppgee import __version__
def test_version():
assert __version__ == '0.1.0'