Skip to content

Commit

Permalink
Update tjsp_ler_tabela_docs_cd_processo.R
Browse files Browse the repository at this point in the history
  • Loading branch information
jjesusfilho authored Mar 4, 2024
1 parent 30ebc06 commit 7957698
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions R/tjsp_ler_tabela_docs_cd_processo.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,61 @@
#' @export
#'
tjsp_ler_tabela_docs_cd_processo <- function(arquivos = NULL, diretorio = "."){

if (is.null(arquivos)) {

arquivos <- list.files(diretorio,full.names = TRUE)

}

pb <- progress::progress_bar$new(total = length(arquivos))

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

pb$tick()

cd_processo <- stringr::str_extract(.x,"(?<=processo_)\\w+")


cd_processo_pg <- stringr::str_extract(.x,"(?<=processo_pg_)\\w+?(?=_)")
cd_processo_sg <- stringr::str_extract(.x,"(?<=processo_sg_)\\w+")

suppressMessages({

doc <- .x |>
xml2::read_html() |>
xml2::xml_text() |>
stringr::str_extract("(?<=requestScope = )\\X+?(?=;)") |>
jsonlite::fromJSON()


doc_name <- tibble::tibble(doc_name= doc$data$title) |>
tibble::rownames_to_column("id_doc")

paginas <- doc$children[[2]]$data$indicePagina

df <- purrr::imap_dfr(doc$children,~{

url_doc <- .x$data$parametros

pagina_inicial <- .x$data$title |>
stringr::str_extract("\\d+")

pagina_final <- .x$data$title |>
stringr::str_extract("\\d+$")

tibble::tibble(id_doc = .y, pagina_inicial, pagina_final, url_doc) |>
dplyr::mutate(id_doc = as.character(id_doc))

}) |>
dplyr::left_join(doc_name) |>
dplyr::select(id_doc, doc_name, pagina_inicial, pagina_final, url_doc) |>
dplyr::mutate(url_doc = paste0("https://esaj.tjsp.jus.br/pastadigital/getPDF.do?",url_doc)) |>
dplyr::group_by(id_doc) |>
dplyr::ungroup() |>
tibble::add_column(cd_processo, .before =1)

tibble::add_column(cd_processo_pg, .before =1) |>
tibble::add_column(cd_processo_sg, .after = 1) |>
dplyr::mutate(instancia = ifelse(is.na(cd_processo_sg), 1, 2), .after = 2)

})

}, NULL))
}

0 comments on commit 7957698

Please sign in to comment.