Skip to content

Instantly share code, notes, and snippets.

@jjesusfilho
Last active November 1, 2023 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjesusfilho/31b505195dda1080447dcfeaed481c82 to your computer and use it in GitHub Desktop.
Save jjesusfilho/31b505195dda1080447dcfeaed481c82 to your computer and use it in GitHub Desktop.
Consulta processo do tjsp via mni
from zeep import Client
import xmltodict
import json
from dotenv import load_dotenv
import os
import getpass
def consultar_processo(
usuario= None,
senha = None,
numero_processo = None,
cabecalho = True,
incluir_movimentos = False,
data_referencia = None,
incluir_documentos = False,
diretorio = "."
):
if isinstance(numero_processo, list) == False:
return "Número do processo deve ser uma lista"
load_dotenv()
wsdl = 'http://esaj.tjsp.jus.br/mniws/servico-intercomunicacao-2.2.2/intercomunicacao?wsdl'
if usuario is None or senha is None:
usuario = os.getenv("TJSPMNIUSUARIO")
senha = os.getenv("TJSPMNISENHA")
if not usuario or not senha:
usuario = input("Forneça o usuario: ")
senha = getpass.getpass("Forneça a senha: ")
client = Client(wsdl = wsdl)
for p in numero_processo:
try:
with client.settings( raw_response = True, strict = False):
resposta = client.service.consultarProcesso(
idConsultante = usuario,
senhaConsultante = senha,
numeroProcesso = p,
incluirCabecalho = cabecalho,
movimentos = incluir_movimentos,
dataReferencia = data_referencia,
incluirDocumentos = incluir_documentos
)
dict_data = xmltodict.parse(resposta.content,
process_namespaces= True,
attr_prefix = '',
namespaces = {'http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2.2':None,
'http://www.cnj.jus.br/intercomunicacao-2.2.2':None,
'http://www.cnj.jus.br/mni/cda': None,
'http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/':None}
)
dict_data = dict_data["http://schemas.xmlsoap.org/soap/envelope/:Envelope"]["http://schemas.xmlsoap.org/soap/envelope/:Body"]["consultarProcessoResposta"]["processo"]
del dict_data['dadosBasicos']['xmlns']
json_data = json.dumps(dict_data, indent=4)
arquivo = os.path.join(diretorio, "api_processo_" + p + ".json")
with open(arquivo, "w") as json_file:
json_file.write(json_data)
except:
pass
def baixar_documento(
usuario= None,
senha = None,
numero_processo = None,
documento = None,
diretorio = "."
):
if isinstance(numero_processo, list) == False:
return "Número do processo deve ser uma lista"
load_dotenv()
wsdl = 'http://esaj.tjsp.jus.br/mniws/servico-intercomunicacao-2.2.2/intercomunicacao?wsdl'
if usuario is None or senha is None:
usuario = os.getenv("TJSPMNIUSUARIO")
senha = os.getenv("TJSPMNISENHA")
if not usuario or not senha:
usuario = input("Forneça o usuario: ")
senha = getpass.getpass("Forneça a senha: ")
client = Client(wsdl = wsdl)
for p in numero_processo:
try:
with client.settings( raw_response = True, strict = False):
resposta = client.service.consultarProcesso(
idConsultante = usuario,
senhaConsultante = senha,
numeroProcesso = p,
documento = documento
)
dict_data = xmltodict.parse(resposta.content,
process_namespaces= True,
attr_prefix = '',
namespaces = {'http://www.cnj.jus.br/tipos-servico-intercomunicacao-2.2.2':None,
'http://www.cnj.jus.br/intercomunicacao-2.2.2':None,
'http://www.cnj.jus.br/mni/cda': None,
'http://www.cnj.jus.br/servico-intercomunicacao-2.2.2/':None}
)
dict_data = dict_data["http://schemas.xmlsoap.org/soap/envelope/:Envelope"]["http://schemas.xmlsoap.org/soap/envelope/:Body"]["consultarProcessoResposta"]["processo"]
del dict_data['dadosBasicos']['xmlns']
json_data = json.dumps(dict_data, indent=4)
arquivo = os.path.join(diretorio, "api_processo_documento" + p + ".json")
with open(arquivo, "w") as json_file:
json_file.write(json_data)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment