Skip to content

Commit

Permalink
atualiza coleta de intimaçoes
Browse files Browse the repository at this point in the history
  • Loading branch information
jjesusfilho committed Jun 13, 2024
1 parent 38c4ecd commit 494f158
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 71 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export(tjsp_ler_dispositivo)
export(tjsp_ler_documentos)
export(tjsp_ler_documentos_cd_processo)
export(tjsp_ler_historico_classes)
export(tjsp_ler_intimacoes)
export(tjsp_ler_intimacoes_xml)
export(tjsp_ler_movimentacao)
export(tjsp_ler_partes)
export(tjsp_ler_peticoes)
Expand Down
136 changes: 117 additions & 19 deletions R/tjsp_baixar_intimacoes.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#' Se não informada, uda a data de hoje.
#' @param situacao Opções: "cumprida", "pendente" ou "ambas". Padrão para "ambas".
#' @param natureza_comunicacao Opções: "intimação", "citação" ou "ambas". Padrão para "ambas".
#' @param versao Pode ser csv ou html. Padrão para csv.
#' @param versao Pode ser csv ou xml. Padrão para csv.
#' @param intervalo Padrão para trimestral, ou seja, máximo.
#' @param diretorio Padrão ".", ou seja, o atual.
#'
#' @return csv
#' @return xml
#' @export
#'
tjsp_baixar_intimacoes <- function(cd_foro = "",
Expand All @@ -23,7 +23,7 @@ tjsp_baixar_intimacoes <- function(cd_foro = "",
dt_fim = "",
situacao = "ambas",
natureza_comunicacao = "ambas",
versao = c("csv","html"),
versao = c("xml","csv"),
intervalo = "trimestral",
diretorio = "."){

Expand All @@ -38,12 +38,12 @@ tjsp_baixar_intimacoes <- function(cd_foro = "",

if(dt_inicio == ""){

dt_inicio <- Sys.Date() |> format("%d/%m/%Y")
dt_inicio <- (Sys.Date() - 1) |> format("%d/%m/%Y")
}

if(dt_fim == ""){

dt_fim <- Sys.Date() |> format("%d/%m/%Y")
dt_fim <- (Sys.Date() -1) |> format("%d/%m/%Y")
}

cd_tipo_ato <- switch(natureza_comunicacao,
Expand All @@ -58,13 +58,13 @@ tjsp_baixar_intimacoes <- function(cd_foro = "",

csv = "https://esaj.tjsp.jus.br/intimacoesweb/exportarAtosRecebidosParaCsv.do",

html = "https://esaj.tjsp.jus.br/intimacoesweb/consultarAtosRecebidos.do"
xml= "https://esaj.tjsp.jus.br/intimacoesweb/consultarAtosRecebidos.do"

)

e <- switch(versao,
csv = ".csv",
html = ".html"
xml = ".xml"
)

cd_usuario <- Sys.getenv("ESAJ_CD_USUARIO")
Expand All @@ -75,16 +75,10 @@ tjsp_baixar_intimacoes <- function(cd_foro = "",

purrr::walk2(datas$data_inicial, datas$data_final, ~{

di <- .x
df <- .y

i <- lubridate::dmy(.x) |>
stringr::str_replace_all("\\D","_")

f <- lubridate::dmy(.y) |>
stringr::str_replace_all("\\D","_")

arquivo <- file.path(diretorio,paste0("foro_", cd_foro,"_inicio_",i,"_fim_",f,e))

body <-
corpo <-
list(
conversationId = "",
entity.cdUsuario = cd_usuario,
Expand All @@ -107,15 +101,119 @@ tjsp_baixar_intimacoes <- function(cd_foro = "",
entity.nmVaraOrigem = "",
entity.cdVaraOrigem = "",
dadosConsulta.flArea = "",
dadosConsulta.dtInicioPeriodo = .x,
dadosConsulta.dtFimPeriodo = .x,
dadosConsulta.dtInicioPeriodo = di,
dadosConsulta.dtFimPeriodo = df,
entity.nuProcessoFormat = "",
entity.cdProcesso = "",
dadosConsulta.formaCienciaIntimacao = "",
entity.cdTipoAto = cd_tipo_ato,
entity.ato.flCumprido = ato_fl_cumprido
)

httr::POST(url1, body = body, encode = "form", httr::write_disk(arquivo, overwrite = T))
r1 <- httr::POST(url1, body = corpo, encode = "form") |>
httr::content()


dividir <- `/`

paginas <- r1 |>
xml2::xml_find_first("//*[@id='textQtLinhasRow']/following-sibling::text()") |>
xml2::xml_text() |>
stringr::str_remove_all("\\D+") |>
as.integer() |>
dividir(20) |>
ceiling()

i <- lubridate::dmy(di) |>
stringr::str_replace_all("\\D","_")

f <- lubridate::dmy(df) |>
stringr::str_replace_all("\\D","_")

purrr::walk(0:paginas, ~{

p <- .x

arquivo <- file.path(diretorio,paste0('pagina_',p,"_foro_", cd_foro,"_inicio_",i,"_fim_",f,e))

q <- structure(
list(
scheme = "https",
hostname = "esaj.tjsp.jus.br",
port = NULL,
path = "intimacoesweb/AjaxServlet.ajax",
query = list(
component = "gridPaginada",
filterPaginationID = "/intimacoesweb_gridAtosUsuario",
beanClass = "br.com.softplan.intimacoes.comum.AtoUsuario",
objectPaginationHandler = "br.com.softplan.saj.intimacoesweb.grid.ConsultaAtosRecebidosPaginationHandler",
ejbClass = "",
ejbMethod = "",
pageSize = "20",
page = .x,
currentPage = "0",
paramSize = "0",
orderBy = "null",
orderByDirection = "null",
column0Type = "null",
column0 = "cdAto",
column1Type = "null",
column1 = "cdUsuario",
column2Type = "null",
column2 = "ato.cdProcesso",
column3Type = "null",
column3 = "ato.cdForo",
column4Type = "null",
column4 = "ato.especialidade.cdEspecialidade",
column5Type = "null",
column5 = "ato.cargo.cdCargo",
column6Type = "null",
column6 = "ato.flCumprido",
column7Type = "null",
column7 = "ato.cdTipoAto",
column8Type = "null",
column8 = "intimacaoAutomatica",
column9Type = "null",
column9 = "dtLeitura",
column10Type = "null",
column10 = "ato.dtInclusao",
column11Type = "null",
column11 = "dtIntimacao",
column12Type = "null",
column12 = "nuDiasPrazo",
column13Type = "null",
column13 = "ato.nuProcessoFormat",
column14Type = "null",
column14 = "classeEAssuntoPrincipaisFormatado",
column15Type = "null",
column15 = "usuarioIntimacao.nmUsuario",
column16Type = "null",
column16 = "ato.deTipoMvProcesso",
column17Type = "null",
column17 = "ato.especialidade.nmEspecialidade",
column18Type = "null",
column18 = "ato.cargo.deCargo",
column19Type = "null",
column19 = "ato.tarjasJson",
columnsSize = "20",
objSerializado = "null"
),
params = NULL,
fragment = NULL,
username = NULL,
password = NULL
),
class = "url"
)


q$query$page <- p

parseada <- httr::build_url(q)

httr::GET(parseada, httr::write_disk(arquivo, overwrite = T))

})

})
}
29 changes: 0 additions & 29 deletions R/tjsp_ler_intimacoes.R

This file was deleted.

67 changes: 67 additions & 0 deletions R/tjsp_ler_intimacoes_xml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#' Ler intimações em xml
#'
#' @param arquivos Vetor de arquivos
#' @param diretorio Diretório como alternativa.
#'
#' @return tibble
#' @export
#'
tjsp_ler_intimacoes_xml <- function(arquivos = NULL, diretorio = "."){

if(is.null(arquivos)){

arquivos <- list.files(diretorio, full.names = TRUE, pattern = "xml$")
}

purrr::map_dfr(arquivos, purrr::possibly(~{

x <- .x |>
xml2::read_html() |>
xml2::xml_find_all("//e")

df1 <- purrr::map_dfr(x, ~{

e <- .x |>
xml2::xml_find_first(".") |>
xml2::xml_attr("i")

n <- .x |>
xml2::xml_find_all(".//r") |>
xml2::xml_attr("n")

v <- .x|>
xml2::xml_find_all(".//r") |>
xml2::xml_attr("v")

tibble::tibble(e, n, v)

}) |>
dplyr::mutate(n = snakecase::to_snake_case(n, transliterations = "Latin-ASCII")) |>
tidyr::pivot_wider(names_from = n, values_from = v) |>
tibble::add_column(arquivo = basename(.x), .before = 1)


df2 <- purrr::map2_dfr(df1$e, df1$ato_tarjas_json, purrr::possibly(~{

.y |>
jsonlite::fromJSON() |>
dplyr::pull(deTarja) |>
stringr::str_c(collapse = "|") |>
tibble::tibble(tarjas = _) |>
tibble::add_column(e = .x)
}, NULL))

df1 |>
dplyr::left_join(df2, by = dplyr::join_by("e")) |>
dplyr::relocate(tarjas, .before = ato_tarjas_json) |>
dplyr::mutate(ato_tarjas_json = NULL) |>
dplyr::mutate(hora_coleta = Sys.time())


},NULL), .progress = TRUE)

}




6 changes: 3 additions & 3 deletions man/tjsp_baixar_intimacoes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions man/tjsp_ler_intimacoes.Rd

This file was deleted.

19 changes: 19 additions & 0 deletions man/tjsp_ler_intimacoes_xml.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 494f158

Please sign in to comment.