UNPKG

brazilian-courts-scrappers

Version:

Data scrapper para fazer raspagem de dados de processos judiciais dos portais de tribunais do Brasil.

221 lines 10.3 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const ScrappedProcesso_1 = __importDefault(require("../data-structures/ScrappedProcesso")); const ScrappedUnidadeJurisdicional_1 = __importDefault(require("../data-structures/ScrappedUnidadeJurisdicional")); const ProcessoScrapper_1 = __importDefault(require("./ProcessoScrapper")); const Pje1gTjbaAndamentosScrapper_1 = __importDefault(require("./Pje1gTjbaAndamentosScrapper")); const Pje1gTjbaPartesScrapper_1 = __importDefault(require("./Pje1gTjbaPartesScrapper")); const utils_1 = require("../utils"); class Pje1gTjbaProcessoScrapper extends ProcessoScrapper_1.default { constructor(doc) { super(doc); this.doc = doc; } fetchProcessoInfo() { const _super = Object.create(null, { fetchProcessoInfo: { get: () => super.fetchProcessoInfo } }); return __awaiter(this, void 0, void 0, function* () { return _super.fetchProcessoInfo.call(this); }); } checkProcessoHomepage() { return super.checkProcessoHomepage(this.doc.URL, Pje1gTjbaProcessoScrapper.IGNORE_URLS_CONTAINING, Pje1gTjbaProcessoScrapper.PROCESSO_HOME_PATH_PART); } loadPageCheckpoints() { this.divMaisDetalhes = this.doc.querySelector("#maisDetalhes"); } ScrappeProcessoInfo() { return __awaiter(this, void 0, void 0, function* () { const andamentos = yield this.getAndamentos(); const { poloAtivo, poloPassivo, outros } = this.getPartes(); return new ScrappedProcesso_1.default(this.getNumero(), "pje1gTjba", poloAtivo, poloPassivo, outros, andamentos, this.getPedidos(), this.getUrl(), this.getDataDistribuicao(), this.getValorDaCausa(), this.getCausaDePedir(), this.getJuizo(), this.getJuizAtual(), this.getAudienciaFutura(), this.getTipoDeAcao(), this.getSegredoJustica(), this.getNumeroProcessoPrincipal(), this.getNumeroRegional(), this.getNumerosIncidentes(), this.getNumerosProcessosRelacionados()); }); } getNumero() { const containerNumeroProcesso = this.doc.querySelector("a.titulo-topo:has(i)"); const classAndNumeroProcessoString = containerNumeroProcesso.firstChild.textContent.trim(); return utils_1.REGEX_CNJ_NUMBER.exec(classAndNumeroProcessoString)[0]; } getNumeroRegional() { return null; } getUrl() { return null; } getDataDistribuicao() { const params = { parentElement: this.divMaisDetalhes, firstGuessQuerySelector: "dl > dt:nth-child(7)", IterableElementsQuerySelector: "dl dt", partialTextToSearch: "autuação", }; const dateString = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params); return this.getDateFromPjeTjbaDateString(dateString); } getDateFromPjeTjbaDateString(dateStr, timeStr = "00:00") { const dateArray = dateStr.split(" "); const meses = { jan: "01", fev: "02", mar: "03", abr: "04", mai: "05", jun: "06", jul: "07", ago: "08", set: "09", out: "10", nov: "11", dez: "12", }; dateArray[1] = meses[dateArray[1].toLowerCase()]; const iso8601DateString = `${dateArray[2]}-${dateArray[1]}-${dateArray[0]}T${timeStr}-03:00`; return new Date(iso8601DateString); } getValorDaCausa() { const params = { parentElement: this.divMaisDetalhes, firstGuessQuerySelector: "dl > dt:nth-child(11)", IterableElementsQuerySelector: "dl dt", partialTextToSearch: "valor da causa", }; const valorDaCausaString = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params); let valorDaCausa = valorDaCausaString.trim().replace(/(R\$ )|(\.)/g, ""); return parseFloat(valorDaCausa.replace(",", ".")); } getTipoDeAcao() { const params = { parentElement: this.divMaisDetalhes, firstGuessQuerySelector: "dl > dt:nth-child(1)", IterableElementsQuerySelector: "dl dt", partialTextToSearch: "classe judicial", }; const tipoDeAcaoFullString = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params).trim(); const tipoDeAcaoId = tipoDeAcaoFullString.match(Pje1gTjbaProcessoScrapper.PJE1G_TJBA_ASSUNTO_OU_CLASSE_ID); const tipoDeAcaoNome = tipoDeAcaoFullString.match(Pje1gTjbaProcessoScrapper.PJE1G_TJBA_ASSUNTO_OU_CLASSE_NOME); return [ { id: tipoDeAcaoId ? Number(tipoDeAcaoId[0]) : null, valor: tipoDeAcaoNome ? tipoDeAcaoNome[0].trim() : null, }, ]; } getCausaDePedir() { const params = { parentElement: this.divMaisDetalhes, firstGuessQuerySelector: "dl > dt:nth-child(3)", IterableElementsQuerySelector: "dl dt", partialTextToSearch: "assunto", }; const causaDePedirFullString = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params).trim(); const causaDePedirId = causaDePedirFullString.match(Pje1gTjbaProcessoScrapper.PJE1G_TJBA_ASSUNTO_OU_CLASSE_ID); const causaDePedirNome = causaDePedirFullString.match(Pje1gTjbaProcessoScrapper.PJE1G_TJBA_ASSUNTO_OU_CLASSE_NOME); return [ { id: causaDePedirId ? Number(causaDePedirId[0]) : null, valor: causaDePedirNome ? causaDePedirNome[0].trim() : null, }, ]; } getSegredoJustica() { const params = { parentElement: this.divMaisDetalhes, firstGuessQuerySelector: "dl > dt:nth-child(13)", IterableElementsQuerySelector: "dl dt", partialTextToSearch: "segredo de justiça", }; const projudiSegredoJusticaString = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params); return projudiSegredoJusticaString.toLowerCase() === "sim"; } getJuizo() { const params = { parentElement: this.divMaisDetalhes, firstGuessQuerySelector: "div:nth-child(2) > dl > dt", IterableElementsQuerySelector: "dl dt", partialTextToSearch: "órgão julgador", }; const juizoName = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params); return new ScrappedUnidadeJurisdicional_1.default(juizoName); } getJuizAtual() { return null; } getNumeroProcessoPrincipal() { return undefined; //TODO: encontrar um processo que tenha processo principal para localizar a informação. // const params = { // parentElement: this.divMaisDetalhes, // firstGuessQuerySelector: 'div:nth-child(2) > dl > dt', // IterableElementsQuerySelector: 'dl dt', // partialTextToSearch: 'órgão julgador' // } // const processoPrincipal = super.getValueFollowingCellSearchedByTextContent(params) // return processoPrincipal.toLowerCase().includes('o próprio') ? null : processoPrincipal } getNumerosIncidentes() { return []; } getNumerosProcessosRelacionados() { return []; //TODO: encontrar um processo que tenha processos dependentes para localizar a informação. // const params = { // parentElement: this.divMaisDetalhes, // firstGuessQuerySelector: 'div:nth-child(2) > dl > dt', // IterableElementsQuerySelector: 'dl dt', // partialTextToSearch: 'órgão julgador' // } // const processosRelacionados = super.getValueFollowingCellSearchedByTextContent(params).trim() // return processosRelacionados ? [processosRelacionados] : null } getPartes() { const partesScrapper = new Pje1gTjbaPartesScrapper_1.default(this.doc); const partes = partesScrapper.fetchParticipantesInfo(); if (!partes) { return { poloAtivo: null, poloPassivo: null, outros: null, }; } return partes; } getAndamentos() { return __awaiter(this, void 0, void 0, function* () { const scrapper = new Pje1gTjbaAndamentosScrapper_1.default(this.doc); return yield scrapper.fetchAndamentosInfo(); }); } getPedidos() { return []; } getAudienciaFutura() { // TODO: Procurar processo com audiência marcada para ver como o PJe mostra. // 'navbar:linkAbaAudiencia' // const audienciaProjudiDateString = lastRelevantAudiencia.observacao.match(this.PROJUDI_EXTENDED_DATE_REGEX)[0] // const audienciaFutura = {...lastRelevantAudiencia, // data: this.getDatFomPjeTjbaDateString(audienciaProjudiDateString), // } return null; } } Pje1gTjbaProcessoScrapper.PROCESSO_HOME_PATH_PART = "/pje/Processo/ConsultaProcesso/Detalhe/"; Pje1gTjbaProcessoScrapper.IGNORE_URLS_CONTAINING = [ "https://pje.tjba.jus.br/pje/downloadBinario.seam", ]; Pje1gTjbaProcessoScrapper.PJE1G_TJBA_ASSUNTO_OU_CLASSE_ID = /(?<=\()\d*(?=\)$)/g; Pje1gTjbaProcessoScrapper.PJE1G_TJBA_ASSUNTO_OU_CLASSE_NOME = /.*(?=\(\d*\)$)/g; exports.default = Pje1gTjbaProcessoScrapper; //# sourceMappingURL=Pje1gTjbaProcessoScrapper.js.map