brazilian-courts-scrappers
Version:
Data scrapper para fazer raspagem de dados de processos judiciais dos portais de tribunais do Brasil.
219 lines • 9.86 kB
JavaScript
"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 Pje1gTrt5AndamentosScrapper_1 = __importDefault(require("./Pje1gTrt5AndamentosScrapper"));
const Pje1gTrt5PartesScrapper_1 = __importDefault(require("./Pje1gTrt5PartesScrapper"));
const utils_1 = require("../utils");
class Pje1gTrt5ProcessoScrapper 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, Pje1gTrt5ProcessoScrapper.IGNORE_URLS_CONTAINING, Pje1gTrt5ProcessoScrapper.PROCESSO_HOME_PATH_PART);
}
loadPageCheckpoints() {
return __awaiter(this, void 0, void 0, function* () {
this.elResumoProcesso = this.doc.querySelector("pje-resumo-processo");
this.divDetails = yield this.getDetailsDiv();
this.divDetails = this.divDetails.cloneNode(true);
this.closeDetailsDiv();
});
}
getDetailsDiv() {
return __awaiter(this, void 0, void 0, function* () {
const expandDetailsButton = this.doc.querySelector("[aria-label*='resumo do processo']");
expandDetailsButton.click();
return yield (0, utils_1.waitForElement)("pje-parte-processo > section > ul", this.doc, {
returnElementSelector: "#processo > div",
});
});
}
closeDetailsDiv() {
this.doc.querySelector("a:has(~ pje-autuacao)").click();
}
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(), "pje1gTrt5", poloAtivo, poloPassivo, outros, andamentos, this.getPedidos(), this.getUrl(), this.getDataDistribuicao(), this.getValorDaCausa(), this.getCausaDePedir(), this.getJuizo(), this.getJuizAtual(), yield this.getAudienciaFutura(), this.getTipoDeAcao(), this.getSegredoJustica(), this.getNumeroProcessoPrincipal(), this.getNumeroRegional(), this.getNumerosIncidentes(), this.getNumerosProcessosRelacionados());
});
}
getNumero() {
const containerNumeroProcesso = this.doc.querySelector("[aria-label*='Abre o resumo do processo']");
return containerNumeroProcesso.textContent.trim();
}
getNumeroRegional() {
return null;
}
getUrl() {
return new URL(this.doc.URL);
}
getDataDistribuicao() {
const params = {
parentElement: this.elResumoProcesso,
firstGuessQuerySelector: "#dataAutuacao + dd",
IterableElementsQuerySelector: "dl dt",
partialTextToSearch: "Autuado",
};
const dateString = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params);
return this.getDateFromPjeTrt1gDateString(dateString);
}
getDateFromPjeTrt1gDateString(dateTimeStr) {
dateTimeStr = dateTimeStr.replace(" ", "/");
const dateArray = dateTimeStr.split("/");
const iso8601DateString = `${dateArray[2]}-${dateArray[1]}-${dateArray[0]}T${dateArray[3]}-03:00`;
return new Date(iso8601DateString);
}
getValorDaCausa() {
const params = {
parentElement: this.elResumoProcesso,
firstGuessQuerySelector: "#valorCausa",
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 containerDescricaoProcesso = this.doc.querySelector("pje-descricao-processo");
const stringTipoProcesso = containerDescricaoProcesso
.querySelector("span:first-child")
.querySelector("span:last-child")
.textContent.trim();
const tipoDeAcaoNome = Pje1gTrt5ProcessoScrapper.tiposAcao[stringTipoProcesso];
return [
{
id: null,
valor: tipoDeAcaoNome,
},
];
}
getCausaDePedir() {
var _a;
const detailsList = this.divDetails.querySelector("div:first-child > dl:only-child");
const params = {
parentElement: detailsList,
firstGuessQuerySelector: "dt:last-of-type",
IterableElementsQuerySelector: "*",
partialTextToSearch: "Assunto(s)",
};
const causaDePedir = (_a = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params)) === null || _a === void 0 ? void 0 : _a.trim();
return [
{
id: null,
valor: causaDePedir,
},
];
}
getSegredoJustica() {
//TODO: descobrir um processo em segredo de justiça para encontrar onde fica a informação
return null;
}
getJuizo() {
const detailsList = this.divDetails.querySelector("div:first-child > dl:only-child");
const params = {
parentElement: detailsList,
firstGuessQuerySelector: "dt:first-child",
IterableElementsQuerySelector: "dl dt",
partialTextToSearch: "Órgão julgador",
};
const nomeOriginalSistemaJustica = (0, utils_1.getValueFollowingCellSearchedByTextContent)(params);
const juizo = new ScrappedUnidadeJurisdicional_1.default(nomeOriginalSistemaJustica);
return juizo;
}
getJuizAtual() {
return null;
}
getNumeroProcessoPrincipal() {
return null;
//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 relacionados 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 Pje1gTrt5PartesScrapper_1.default(this.divDetails);
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 Pje1gTrt5AndamentosScrapper_1.default(this.doc);
return yield scrapper.fetchAndamentosInfo();
});
}
getPedidos() {
return [];
}
getAudienciaFutura() {
return __awaiter(this, void 0, void 0, function* () {
// const audienciasUrl = processoUrl.replace(
// "/detalhe",
// "/audiencias-sessoes"
// );
// TODO: Procurar processo com audiência marcada para ver como o PJe mostra.
return null;
});
}
}
Pje1gTrt5ProcessoScrapper.PROCESSO_HOME_PATH_PART = "/pjekz/processo/";
Pje1gTrt5ProcessoScrapper.IGNORE_URLS_CONTAINING = [
"https://pje.trt5.jus.br/pjekz/assets/pdf/web/viewer.html",
"https://pje.trt5.jus.br/pjekz/downloadBinario.seam",
];
Pje1gTrt5ProcessoScrapper.tiposAcao = {
ATOrd: "Ação Trabalhista Ordinária",
};
exports.default = Pje1gTrt5ProcessoScrapper;
//# sourceMappingURL=Pje1gTrt5ProcessoScrapper.js.map