0% found this document useful (0 votes)
7 views3 pages

Codigo Bom

Uploaded by

selfieguy69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Codigo Bom

Uploaded by

selfieguy69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

código do para q ta podendo

import requests
import json
from datetime import datetime
import time
from unicodedata import normalize

def adjust_date(date_str):
try:
return datetime.strptime(date_str, "%Y-%m-%d").date().strftime("%d/%m/%Y")
except ValueError:
return date_str

def fetch_data(page_number):
headers = {
'Accept': '*/*',
'Accept-Language': 'pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7',
'Connection': 'keep-alive',
'Content-Type': 'application/json',
'Origin': 'https://jurisprudencia.tjpa.jus.br',
'Referer': 'https://jurisprudencia.tjpa.jus.br/?current=n_2_n&size=n_20_n',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
'Authorization': 'Bearer search-zcw171fwuz5e2eo44z9si9wh',
}

json_data = {
'query': '',
'facets': {
'pessoas': {'type': 'value', 'size': 250},
'orgaojulgadorcolegiado': {'type': 'value', 'size': 250},
'origem': {'type': 'value', 'size': 250},
'tipo': {'type': 'value', 'size': 250},
},
'page': {'size': 0, 'current': page_number},
'filters': {
'all': [
{
'any': [
{
'origem': 'Tribunal de Justiça do Estado do Pará',
},
],
},
{
'any': [
{
'datajulgamento': {
'from': '2024-08-20T00:00:00.000Z',
'to': '2024-09-02T23:59:59.999Z',
},
},
],
},
],
},
}

successful = False
t1 = time.time()
while not successful:
try:
response = requests.post(

'https://jurisprudencia.tjpa.jus.br/api/as/v1/engines/jurisprudencia-23-11-23/
search.json',
headers=headers,
json=json_data
)
print(f"Response Status Code: {response.status_code}")
print(f"Response Content: {response.content}")

if response.status_code == 200:
return json.loads(response.content)
else:
t2 = time.time()
if (t2 - t1) < 60:
print(f'Error {response.status_code}, retrying in 5
seconds...', end='\r')
time.sleep(5)
else:
raise Exception(f'Maximum timeout reached, aborting.')
except Exception as e:
print(f"Exception occurred: {e}")
time.sleep(5)

def get_formatted_data(page_number):
data = fetch_data(page_number)
if not data:
print("No data returned from fetch_data.")
return []

all_data = data.get('result', {}).get('data', {}).get('items', [])


if not all_data:
print("No items found in the response data.")
return []

formatted_data = []
for item in all_data:
formatted_data.append({
"outro": {
"urlOriginal": item.get("url", ""),
"Classe/Assunto": item.get("classe", ""),
"source": "tjpa"
},
"numeroProcesso": item.get("numeroProcesso", ""),
"ementa": normalize('NFKD', item.get("ementa", "")),
"tribunal": "TJPA",
"ministroRelator": item.get("relator", {}).get("nome", "N/A"),
"nomeOrgaoJulgador": item.get("orgaoJulgador", {}).get("nome", ""),
"dataPublicacao": adjust_date(item.get('dataPublicacao', '')),
"tipoDeDecisao": item.get("tipoDecisao", "")
})
return formatted_data
page_number = 1
formatted_data = get_formatted_data(page_number)
if formatted_data:
for data in formatted_data:
print(json.dumps(data, indent=2, ensure_ascii=False))
else:
print("No formatted data available.")

You might also like