Skip to content

Commit

Permalink
New method added "get tipo participante" and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eudesrodrigo committed Jan 23, 2022
1 parent 9e4291c commit cd7d64a
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 86 deletions.
49 changes: 32 additions & 17 deletions brFinance/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
GetCategoriesResponse,
GetSearchResponse,
GetReportResponse,
GetTipoParticipanteResponse,
GetCadastroInstrumentosTokenResponse,
GetCadastroInstrumentosResponse,
GetEmissorResponse,
GetPesquisaCiaAbertaResponse
)
)

POOL_CONNECTOR = CVMHttpClientConnector()

Expand All @@ -25,25 +26,32 @@ def __init__(self) -> None:
def _http_client(self):
return CVMHttpClient(
session=self._connector
)
)

def get_consulta_externa_cvm_results(
self,
start_date: date = date.today(),
end_date: date = date.today(),
start_date: date = None,
end_date: date = None,
cod_cvm: list = [],
participant_type: list = [1],
category: list = None,
last_ref_date: bool = False
):
):

if (not category) or (category is None):
category = ['EST_-1', 'IPE_-1_-1_-1']

if (not participant_type) or (participant_type is None):
participant_type = ['-1']

response = self._http_client().get_search_results(
cod_cvm=",".join(cod_cvm),
cod_cvm=str(
",".join([str(item) for item in cod_cvm])),
start_date=start_date,
end_date=end_date,
category=",".join(category),
participant_type=str(
",".join([str(item) for item in participant_type])),
last_ref_date=last_ref_date)
response_class = GetSearchResponse(response=response)

Expand Down Expand Up @@ -73,34 +81,41 @@ def get_consulta_externa_cvm_categories(self):
response_class = GetCategoriesResponse(response=response)

return response_class.data()


def get_consulta_externa_cvm_tipo_participante(self):
response = self._http_client().get_enet_consulta_externa()
response_class = GetTipoParticipanteResponse(response=response)

return response_class.data()

def get_consulta_externa_cvm_categories(self):
response = self._http_client().get_enet_consulta_externa()
response_class = GetCategoriesResponse(response=response)

return response_class.data()

def get_cadastro_instrumentos(self, ref_date: date = date.today()):

token_response = self._http_client().get_cadastro_de_instrumentos_token(ref_date=ref_date)
token = GetCadastroInstrumentosTokenResponse(response=token_response).data()


token_response = self._http_client(
).get_cadastro_de_instrumentos_token(ref_date=ref_date)
token = GetCadastroInstrumentosTokenResponse(
response=token_response).data()

response = self._http_client().get_cadastro_de_instrumentos(token=token)
response_class = GetCadastroInstrumentosResponse(response=response)

return response_class.data()

def get_emissor(self):

response = self._http_client().get_emissor()
response_class = GetEmissorResponse(response=response)

return response_class.data()

def get_pesquisa_cia_aberta(self):

response = self._http_client().get_pesquisa_cia_aberta()
response_class = GetPesquisaCiaAbertaResponse(response=response)

return response_class.data()

15 changes: 11 additions & 4 deletions brFinance/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ def get_search_results(
cod_cvm: str,
start_date: date,
end_date: date,
participant_type: str,
category: str,
last_ref_date
):

if (str(cod_cvm)) and (str(cod_cvm) is not None):
cod_cvm = str(cod_cvm).zfill(6)

dataDe = start_date.strftime("%d/%m/%Y")
dataAte = end_date.strftime("%d/%m/%Y")
if start_date and end_date:
dataDe = start_date.strftime("%d/%m/%Y")
dataAte = end_date.strftime("%d/%m/%Y")
periodo = "2"
else:
dataDe = ""
dataAte = ""
periodo = "0"
categoria = category
ultimaDtRef = BOOL_STRING_MAPPER[last_ref_date]

Expand Down Expand Up @@ -62,10 +69,10 @@ def get_search_results(
setorAtividade: '-1',
categoriaEmissor: '-1',
situacaoEmissor: '-1',
tipoParticipante: '-1',
tipoParticipante: '{participant_type}',
dataReferencia: '',
categoria: '{categoria}',
periodo: '2',
periodo: '{periodo}',
horaIni: '',
horaFim: '',
palavraChave:'',
Expand Down
24 changes: 24 additions & 0 deletions brFinance/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ def _parse_get_consulta_externa_cvm_categories(self, html):
return categories


class GetTipoParticipanteResponse():
def __init__(self, response) -> None:
self.response = response

def data(self):
data = self._parse_get_consulta_externa_cvm_tipo_participante(
self.response.text)
return data

def _parse_get_consulta_externa_cvm_tipo_participante(self, html):
cboTipoParticipante = BeautifulSoup(
html, features="lxml").find(id='cboTipoParticipante')

cboTipoParticipante = cboTipoParticipante.find_all('option')

tipo_participante = {}

for option in cboTipoParticipante:
tipo_participante[option.attrs["value"]
] = option.getText()

return tipo_participante


class GetCadastroInstrumentosTokenResponse():
def __init__(self, response) -> None:
self.response = response
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'requests',
'pandas',
'beautifulsoup4',
'lxml'
]


Expand Down
Loading

0 comments on commit cd7d64a

Please sign in to comment.