-
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.
rata para bens, colocado retorno no arquivo puxados_bens, algumas con…
…figurações e movido o env para a raiz do projeto para causar menos instabilidades
- Loading branch information
Showing
2,675 changed files
with
29,864 additions
and
1,964 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PYTHONPATH=/Gastos-DF-Squad12 | ||
#PYTHONPATH=/home/vini/2projeto/Gastos-DF-Squad12 | ||
|
File renamed without changes.
Binary file not shown.
Binary file not shown.
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 |
---|---|---|
@@ -1,71 +1,92 @@ | ||
import requests | ||
import re | ||
from typing import List, Dict, Union | ||
from pydantic import BaseModel | ||
from datetime import date | ||
|
||
# Fazendo a solicitação GET para a API | ||
response = requests.get( | ||
'https://queridodiario.ok.org.br/api/gazettes?territory_ids=5300108&published_since=2024-01-01&published_until=2024-07-01&querystring=%22EXTRATO%20DO%20CONTRATO%20DE%20AQUISI%C3%87%C3%83O%20DE%20BENS%22&excerpt_size=4000&number_of_excerpts=10000&pre_tags=&post_tags=&size=10000&sort_by=descending_date') | ||
class DateRange(BaseModel): | ||
published_since: date | ||
published_until: date | ||
|
||
# Verificando se a solicitação foi bem-sucedida | ||
if response.status_code == 200: | ||
async def puxador_bens1(date_range: DateRange) -> Union[List[Dict[str, Union[str, float]]], int]: | ||
# Formatando as datas no formato americano | ||
published_since_str = date_range.published_since.strftime('%Y-%m-%d') | ||
published_until_str = date_range.published_until.strftime('%Y-%m-%d') | ||
# Fazendo a solicitação GET para a API | ||
response = requests.get( | ||
f'https://queridodiario.ok.org.br/api/gazettes?territory_ids=5300108&published_since={published_since_str}&published_until={published_until_str}&querystring=%22EXTRATO%20DO%20CONTRATO%20DE%20AQUISI%C3%87%C3%83O%20DE%20BENS%22&excerpt_size=4000&number_of_excerpts=10000&pre_tags=&post_tags=&size=10000&sort_by=descending_date') | ||
# Verificando se a solicitação foi bem-sucedida | ||
if response.status_code == 200: | ||
|
||
# Convertendo a resposta para JSON | ||
dados = response.json() | ||
# Convertendo a resposta para JSON | ||
dados = response.json() | ||
|
||
# Acessando a lista de gazettes dentro dos dados | ||
gazettes = dados['gazettes'] | ||
# Acessando a lista de gazettes dentro dos dados | ||
gazettes = dados['gazettes'] | ||
|
||
# Lista para armazenar os dicionários com as informações extraídas | ||
results = [] | ||
|
||
# Conjunto para armazenar as datas já vistas | ||
datas_vistas = set() | ||
# Conjunto para armazenar as datas já vistas | ||
datas_vistas = set() | ||
|
||
# Iterando sobre cada gazette na lista | ||
for gazette in gazettes: | ||
# Acessando a data de cada gazette | ||
data = gazette['date'] | ||
# Iterando sobre cada gazette na lista | ||
for gazette in gazettes: | ||
# Acessando a data de cada gazette | ||
data = gazette['date'] | ||
|
||
# Verificando se a data já foi impressa | ||
if data not in datas_vistas: | ||
print("\nData:", data) | ||
# Adicionando a data ao conjunto de datas vistas | ||
datas_vistas.add(data) | ||
# Verificando se a data já foi processada | ||
if data not in datas_vistas: | ||
# Adicionando a data ao conjunto de datas vistas | ||
datas_vistas.add(data) | ||
|
||
# Acessando a lista de excertos de cada gazette | ||
excertos = gazette['excerpts'] | ||
total_diario = 0 | ||
# Acessando a lista de excertos de cada gazette | ||
excertos = gazette['excerpts'] | ||
total_diario = 0 | ||
|
||
# Iterando sobre cada excerto | ||
for excerto in excertos: | ||
# Remover quebras de linha no meio das palavras | ||
excerto = re.sub(r'(\w)-\n(\w)', r'\1\2', excerto) | ||
# Remover todas as quebras de linha | ||
excerto = excerto.replace('\n', ' ') | ||
# Iterando sobre cada excerto | ||
for excerto in excertos: | ||
# Remover quebras de linha no meio das palavras | ||
excerto = re.sub(r'(\w)-\n(\w)', r'\1\2', excerto) | ||
# Remover todas as quebras de linha | ||
excerto = excerto.replace('\n', ' ') | ||
|
||
# Usando expressão regular para encontrar Empresa, CNPJ, Objeto e Valor | ||
empresa_match = re.search(r'(?:FORNECEDOR|empresa)\s+([\w\s\-ÇçÉéÁáÍíÓóÚúÃãÕõâêîôûÂÊÎÔÛäëïöüÄËÏÖÜ]+)\s+.*?CNPJ[\s:nº]*([\d./-]+)', excerto, re.DOTALL) | ||
objeto_match = re.search(r'OBJETO:\s*([^\n,]+?(?:,\s*para atender as demandas)?(?:\s*da Vice-Governadoria)?.*?)\s*VALOR', excerto, re.DOTALL) | ||
valor_match = re.search(r'VALOR (?:DO CONTRATO)?:\s*R\$ ([\d,.]+)', excerto) | ||
# Usando expressão regular para encontrar Empresa, CNPJ, Objeto e Valor | ||
empresa_match = re.search(r'(?:FORNECEDOR|empresa)\s+([\w\s\-ÇçÉéÁáÍíÓóÚúÃãÕõâêîôûÂÊÎÔÛäëïöüÄËÏÖÜ]+)\s+.*?CNPJ[\s:nº]*([\d./-]+)', excerto, re.DOTALL) | ||
objeto_match = re.search(r'OBJETO:\s*([^\n,]+?(?:,\s*para atender as demandas)?(?:\s*da Vice-Governadoria)?.*?)\s*VALOR', excerto, re.DOTALL) | ||
valor_match = re.search(r'VALOR (?:DO CONTRATO)?:\s*R\$ ([\d,.]+)', excerto) | ||
|
||
if empresa_match and objeto_match and valor_match: | ||
# Extraindo a empresa e o CNPJ encontrados | ||
empresa = empresa_match.group(1).strip() | ||
cnpj = empresa_match.group(2).strip() | ||
if empresa_match and objeto_match and valor_match: | ||
# Extraindo a empresa e o CNPJ encontrados | ||
empresa = empresa_match.group(1).strip() | ||
cnpj = empresa_match.group(2).strip() | ||
|
||
# Extraindo o objeto encontrado e removendo parte desnecessária | ||
objeto = objeto_match.group(1).strip() | ||
# Extraindo o objeto encontrado e removendo parte desnecessária | ||
objeto = objeto_match.group(1).strip() | ||
|
||
# Extraindo o valor encontrado | ||
valor = valor_match.group(1) | ||
# Removendo caracteres não numéricos, exceto vírgulas e pontos | ||
valor_limpo = re.sub(r'[^\d,.]', '', valor) | ||
# Removendo pontos extras como separadores de milhar | ||
valor_limpo = valor_limpo.replace('.', '') | ||
# Trocando a vírgula por ponto para ter o formato correto para float | ||
valor_limpo = valor_limpo.replace(',', '.') | ||
# Convertendo o valor para float | ||
valor_float = float(valor_limpo) | ||
total_diario += valor_float | ||
# Extraindo o valor encontrado | ||
valor = valor_match.group(1) | ||
# Removendo caracteres não numéricos, exceto vírgulas e pontos | ||
valor_limpo = re.sub(r'[^\d,.]', '', valor) | ||
# Removendo pontos extras como separadores de milhar | ||
valor_limpo = valor_limpo.replace('.', '') | ||
# Trocando a vírgula por ponto para ter o formato correto para float | ||
valor_limpo = valor_limpo.replace(',', '.') | ||
# Convertendo o valor para float | ||
valor_float = float(valor_limpo) | ||
total_diario += valor_float | ||
|
||
print(f"Empresa: {empresa} -- CNPJ: {cnpj}\nObjeto: {objeto}\nValor: R${valor_float:.2f}") | ||
print(f'Dívidas totais = R${total_diario:.2f}') | ||
else: | ||
# Se a solicitação falhar, imprima o código de status | ||
print("Erro:", response.status_code) | ||
# Adicionando as informações à lista de resultados | ||
results.append({ | ||
"data": data, | ||
"empresa": empresa, | ||
"cnpj": cnpj, | ||
"objeto": objeto, | ||
"valor": valor_float | ||
}) | ||
# não adicionei o total diário à lista de resultados pois pode ser facilmente feito pelo front na hora de montar os gráficos. | ||
# mas ficaria assim: results.append({"data": data, "total_diario": total_diario}) | ||
return results | ||
else: | ||
# Se a solicitação falhar, retorne o código de status | ||
return response.status_code |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
exclude: | ||
- api/venv/ | ||
- venv/ |
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
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.21 KB
api/puxador_bens/routers/__pycache__/puxador_bens_router.cpython-312.pyc
Binary file not shown.
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,29 @@ | ||
from fastapi import APIRouter, HTTPException | ||
from typing import Dict, Any | ||
from pydantic import BaseModel | ||
from datetime import date | ||
#from Back import puxador_bens | ||
#from ...Back import puxador_bens | ||
from Back.puxador_bens import puxador_bens1 | ||
|
||
|
||
router = APIRouter(prefix="/puxador-bens") | ||
|
||
# A data deve ser no formato americano YYYY-MM-DD. | ||
# Se o formato estiver incorreto ou se as datas não forem fornecidas, o FastAPI retornará um erro 422 de validação. | ||
|
||
class DateRange(BaseModel): | ||
published_since: date | ||
published_until: date | ||
|
||
@router.post("/") | ||
async def post_bens(date_range: DateRange): | ||
|
||
result = await puxador_bens1(date_range) | ||
|
||
if isinstance(result, int): | ||
# Se o resultado for um código de status, retorne um erro | ||
raise HTTPException(status_code=result, detail=f"Erro ao acessar a API: {result}") | ||
|
||
return result | ||
|
46 changes: 0 additions & 46 deletions
46
api/venv/lib/python3.12/site-packages/PyYAML-6.0.1.dist-info/METADATA
This file was deleted.
Oops, something went wrong.
43 changes: 0 additions & 43 deletions
43
api/venv/lib/python3.12/site-packages/PyYAML-6.0.1.dist-info/RECORD
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-136 KB
api/venv/lib/python3.12/site-packages/__pycache__/typing_extensions.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-872 Bytes
api/venv/lib/python3.12/site-packages/_yaml/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-18.2 KB
api/venv/lib/python3.12/site-packages/annotated_types/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-3.19 KB
api/venv/lib/python3.12/site-packages/anyio/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-200 Bytes
api/venv/lib/python3.12/site-packages/anyio/_backends/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-119 KB
api/venv/lib/python3.12/site-packages/anyio/_backends/__pycache__/_asyncio.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-196 Bytes
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-6.21 KB
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_eventloop.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-949 Bytes
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_resources.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-27.6 KB
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_sockets.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-2.3 KB
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_streams.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-6.62 KB
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_subprocesses.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-6.84 KB
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_tasks.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-3.49 KB
api/venv/lib/python3.12/site-packages/anyio/_core/__pycache__/_testing.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-2.29 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-14.8 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_eventloop.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-1.6 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_resources.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-9.67 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_sockets.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-8.25 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_streams.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-3.17 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_subprocesses.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-4.08 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_tasks.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-2.78 KB
api/venv/lib/python3.12/site-packages/anyio/abc/__pycache__/_testing.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-198 Bytes
api/venv/lib/python3.12/site-packages/anyio/streams/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-8.11 KB
api/venv/lib/python3.12/site-packages/anyio/streams/__pycache__/text.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-2.65 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-26.8 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/_compat.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-133 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/core.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-14.4 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/exceptions.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-21 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/parser.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-24 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/testing.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-48.3 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/types.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-25.7 KB
api/venv/lib/python3.12/site-packages/click/__pycache__/utils.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-1.66 KB
api/venv/lib/python3.12/site-packages/dotenv/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-364 Bytes
api/venv/lib/python3.12/site-packages/dotenv/__pycache__/__main__.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-9.51 KB
api/venv/lib/python3.12/site-packages/dotenv/__pycache__/cli.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-16.1 KB
api/venv/lib/python3.12/site-packages/dotenv/__pycache__/main.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-9.77 KB
api/venv/lib/python3.12/site-packages/dotenv/__pycache__/parser.cpython-312.pyc
Binary file not shown.
Binary file removed
BIN
-216 Bytes
api/venv/lib/python3.12/site-packages/dotenv/__pycache__/version.cpython-312.pyc
Binary file not shown.
Oops, something went wrong.