feat: add frequency confirmation
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import date
|
||||
from ppgee.errors import RequestException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
URL_BASE = "https://www.ppgee.ufmg.br/ppgeenet"
|
||||
|
||||
|
||||
class PPGEE:
|
||||
@@ -17,6 +19,12 @@ class PPGEE:
|
||||
await self.login()
|
||||
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 with self.session.request(method, url, **kwargs) as resp:
|
||||
if resp.status != 200:
|
||||
@@ -27,25 +35,23 @@ class PPGEE:
|
||||
|
||||
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
|
||||
)
|
||||
data: dict[str, str] = {"login": self.user, "senha": self.password}
|
||||
return await self._request("post", f"{URL_BASE}/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"
|
||||
)
|
||||
return await self._request("get", f"{URL_BASE}/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:
|
||||
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()
|
||||
return await self._request("get", f"{URL_BASE}/logoff.php")
|
||||
|
||||
Reference in New Issue
Block a user