feat: add frequency confirmation

This commit is contained in:
2022-10-03 21:33:36 -03:00
parent 693e92c789
commit d882cde772

View File

@@ -1,9 +1,11 @@
import aiohttp import aiohttp
import asyncio import asyncio
import logging import logging
from datetime import date
from ppgee.errors import RequestException from ppgee.errors import RequestException
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
URL_BASE = "https://www.ppgee.ufmg.br/ppgeenet"
class PPGEE: class PPGEE:
@@ -17,6 +19,12 @@ class PPGEE:
await self.login() await self.login()
return self return self
async def __aexit__(self, exc_type, exc, tb) -> None:
await self.logoff()
await asyncio.sleep(1)
if self.session:
await self.session.close()
async def _request(self, method: str, url: str, **kwargs) -> str: async def _request(self, method: str, url: str, **kwargs) -> str:
async with self.session.request(method, url, **kwargs) as resp: async with self.session.request(method, url, **kwargs) as resp:
if resp.status != 200: if resp.status != 200:
@@ -27,25 +35,23 @@ class PPGEE:
async def login(self) -> str: async def login(self) -> str:
logger.debug("Sending request to login.") logger.debug("Sending request to login.")
data = {"login": self.user, "senha": self.password} data: dict[str, str] = {"login": self.user, "senha": self.password}
return await self._request( return await self._request("post", f"{URL_BASE}/login.php", data=data)
"post", "https://www.ppgee.ufmg.br/ppgeenet/login.php", data=data
)
async def frequency(self) -> str: async def frequency(self) -> str:
logger.debug("Sending request to frequency.") logger.debug("Sending request to frequency.")
return await self._request( return await self._request("get", f"{URL_BASE}/afreq.php")
"get", "https://www.ppgee.ufmg.br/ppgeenet/afreq.php"
) async def frequency_confirmation(self) -> str:
logger.debug("Sending request to confirm frequency.")
today = date.today()
data: dict[str, str] = {
"freqano": str(today.year),
"freqmes": str(today.month),
"confirma": "checkbox",
}
return await self._request("POST", f"{URL_BASE}/afreqpasso2.php", data=data)
async def logoff(self) -> str: async def logoff(self) -> str:
logger.debug("Sending request to logoff.") logger.debug("Sending request to logoff.")
return await self._request( return await self._request("get", f"{URL_BASE}/logoff.php")
"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()