Skip to content

Commit

Permalink
Merge pull request #72 from ImpulsoGov/correcao_parametros_requisicao…
Browse files Browse the repository at this point in the history
…_sisab

Corrige ETL de Indicadores do SISAB
  • Loading branch information
waltmatheus committed Oct 6, 2023
2 parents d41221f + bca7d43 commit 40f0d07
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
35 changes: 33 additions & 2 deletions src/impulsoetl/sisab/indicadores_municipios/extracao.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@
}


def contar_linhas_cabecalho(resposta_requisicao, colunas_alvo):
"""Conta o número de linhas que compõe o cabeçalho do arquivo csv"""

linhas_cabecalho = 0
linhas = resposta_requisicao.splitlines()

for linha in linhas:

if not linha.strip():
continue

if all(coluna in linha for coluna in colunas_alvo):
break

linhas_cabecalho += 1

return linhas_cabecalho


def verifica_colunas(df_extraido: pd.DataFrame) -> int:
"""Verifica se 'Dataframe' possui 13 colunas como esperado"""
return df_extraido.shape[1]
Expand Down Expand Up @@ -100,10 +119,23 @@ def extrair_indicadores(
data=payload,
timeout=120,
)

resposta_requisicao = response.text
colunas_alvo = [
"Denominador Utilizado",
"Denominador Identificado",
"Denominador Estimado",
"Cadastro",
"Base Externa",
]
numero_linhas_cabecalho = contar_linhas_cabecalho(
resposta_requisicao, colunas_alvo
)

df_extraido = pd.read_csv(
StringIO(response.text),
delimiter=";",
header=10,
header=numero_linhas_cabecalho,
encoding="ISO-8859-1",
)
df_extraido = df_extraido.drop(
Expand All @@ -118,4 +150,3 @@ def extrair_indicadores(
)

return df_extraido

8 changes: 4 additions & 4 deletions src/impulsoetl/sisab/parametros_requisicao.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def head(url):
"Sec-Fetch-User": "?1",
"Sec-Fetch-Dest": "document",
"Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7",
"Cookie": "BIGipServerpool_sisab_jboss="
+ cookies[0]["BIGipServerpool_sisab_jboss"]
+ ";JSESSIONID="
+ cookies[0]["JSESSIONID"],
"Cookie": "JSESSIONID="
+ cookies[0]["JSESSIONID"]
+ ";BIGipServerEI216T7OCd1WTwga/7fQVQ="
+ cookies[0]["BIGipServerEI216T7OCd1WTwga/7fQVQ"],
}
return headers, vs

0 comments on commit 40f0d07

Please sign in to comment.