-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from manrodrigues/develop
Develop
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import configparser | ||
|
||
|
||
class ProjectConfigs: | ||
_configs = None | ||
|
||
def __init__(self): | ||
raise RuntimeError('Call instance() instead') | ||
|
||
@classmethod | ||
def configs(cls): | ||
if cls._configs is None: | ||
cls._configs = _read_configs() | ||
return cls._configs | ||
|
||
|
||
def _read_configs(): | ||
parser = configparser.ConfigParser() | ||
parser.read('./credentials.ini') | ||
project_configs = parser['credentials'] | ||
|
||
project_configs['email'] = project_configs.get('email') | ||
project_configs['nome'] = project_configs.get('nome') | ||
project_configs['numero_matricula'] = project_configs.get('numero_matricula') | ||
project_configs['credencial_id'] = project_configs.get('credencial_id') | ||
|
||
return project_configs | ||
|
||
|
||
configs = ProjectConfigs.configs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from configs import ProjectConfigs | ||
from utils import * | ||
|
||
configs = ProjectConfigs.configs() | ||
|
||
session, auth = get_auth(configs['credencial_id'], configs['nome'], configs['email'], configs['numero_matricula']) | ||
|
||
session, usuario = get_usuario(auth, session) | ||
|
||
session, temporadas = get_temporadas(session) | ||
|
||
session, vagas_compra, disopnivel_compra = check_disponibilidade(temporadas, session) | ||
|
||
session, vagas_sorteio, disopnivel_venda = check_disponibilidade(temporadas, session, tipo="SORTEIO") | ||
|
||
print(disopnivel_compra, disopnivel_venda) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
configparser==6.0.0 | ||
requests==2.31.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import requests | ||
|
||
auth_endpoint = "https://reservabertioga.sescsp.org.br/bertioga-web/usuario/meu-perfil/authenticate" | ||
base_availability_endpoint = "https://reservabertioga.sescsp.org.br/bertioga-web/periodo/ano/" | ||
usuario_endpoint = "https://reservabertioga.sescsp.org.br/bertioga-web/usuario" | ||
temporadas_endpoint = "https://reservabertioga.sescsp.org.br/bertioga-web/temporadas" | ||
|
||
|
||
def get_auth(credencial_id, nome, email, numero_matricula, session=None): | ||
payload = { | ||
'id': credencial_id, | ||
'nome': nome, | ||
'email': email, | ||
'numeroMatricula': numero_matricula | ||
} | ||
|
||
if session is None: | ||
s = requests.Session() | ||
else: | ||
s = session | ||
auth = s.post(auth_endpoint, json=payload) | ||
assert auth.status_code == 200 | ||
return s, auth.json() | ||
|
||
|
||
def get_usuario(payload, s): | ||
usuario = s.get(usuario_endpoint, json=payload) | ||
assert usuario.status_code == 200 | ||
return s, usuario.json() | ||
|
||
|
||
def get_temporadas(s): | ||
temporadas = s.get(temporadas_endpoint) | ||
assert temporadas.status_code == 200 | ||
return s, temporadas.json() | ||
|
||
|
||
def check_disponibilidade(temporadas, s, tipo="COMPRA"): | ||
vagas = list() | ||
disponivel = False | ||
for ano in temporadas.keys(): | ||
print(ano) | ||
endpoint_ano = f"{base_availability_endpoint}{ano}/mes/" | ||
for mes in temporadas[ano]: | ||
endpoint_mes = f"{endpoint_ano}{mes}?tipo={tipo}" | ||
print(f"{endpoint_mes}") | ||
disponibilidade = s.get(endpoint_mes) | ||
assert disponibilidade.status_code == 200 | ||
if len(disponibilidade.json()) > 0: | ||
disponivel = True | ||
vagas.append(disponibilidade.json()) | ||
return s, vagas, disponivel |