Skip to content

Commit

Permalink
pequena correção.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjesusfilho committed Mar 5, 2024
1 parent 0e51395 commit d527146
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 94 deletions.
79 changes: 41 additions & 38 deletions R/tjsp_baixar_cpopg_docs_cd_processo.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,56 +7,59 @@
#' @export
#'
tjsp_baixar_docs_cd_processo <- function(df,diretorio = "."){

lista <- df |>
dplyr::group_split(cd_processo_pg)


httr::set_config(httr::config(ssl_verifypeer = FALSE))


uri_pg <- "https://esaj.tjsp.jus.br/cpopg/search.do?gateway=true"

uri_sg <- "https://esaj.tjsp.jus.br/cposg/search.do?gateway=true"


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


purrr::walk(lista, purrr::possibly(~{

pb$tick()


cd_processo <- .x$cd_processo_pg |> unique()


if (!all(is.na(.x$cd_processo_sg))) {

sg <- unique(.x$cd_processo_sg)

r1 <- httr::GET(paste0("https://esaj.tjsp.jus.br/cposg/show.do?processo.codigo=",sg , "&gateway=true"))

url1 <- paste0("https://esaj.tjsp.jus.br/cposg/verificarAcessoPastaDigital.do?cdProcesso=", sg,"&conversationId=&_=1599440192646")


} else {




r1 <- httr::GET(paste0("https://esaj.tjsp.jus.br/cposg/show.do?processo.codigo=",cd_processo , "&gateway=true"))


url1 <- paste0("https://esaj.tjsp.jus.br/cpopg/abrirPastaDigital.do?processo.codigo=",cd_processo)

}

r2 <- url1 |>
httr::GET() |>
httr::content("text") |>
httr::GET()

tjsp_baixar_docs_cd_processo1(.x$cd_processo_pg, .x$id_doc, .x$pagina_inicial, .x$url_doc, diretorio)


},NULL))

}


Expand All @@ -75,26 +78,26 @@ tjsp_baixar_docs_cd_processo1 <- function(cd_processo = NULL,
pagina_inicial = NULL,
urls = NULL,
diretorio = NULL){



id <- stringr::str_c(cd_processo,
"_id_doc_",id_doc,
"_pagina_inicial_",pagina_inicial
)

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


purrr::walk2(urls,id,purrr::possibly(~{

pb$tick()

arquivo <- file.path(diretorio,paste0(.y,".pdf"))

httr::GET(.x,httr::write_disk(arquivo,overwrite = TRUE))

},NULL))

}

66 changes: 33 additions & 33 deletions R/tjsp_baixar_tabela_cd_processo.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,62 @@
tjsp_baixar_tabela_cd_processo <- function (cd_processo = NULL, diretorio = ".")
{
httr::set_config(httr::config(ssl_verifypeer = FALSE))


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

purrr::walk(cd_processo, purrr::possibly(~{

arquivo <- file.path(diretorio,paste0("tabela_cd_processo_",.x,".html"))


r1 <- .x |>
paste0("https://esaj.tjsp.jus.br/cpopg/show.do?processo.codigo=", ... = _, "&gateway=true") |>
httr::GET()


if (

r1 |>
httr::content() |>
httr::content() |>
xml2::xml_find_first("boolean(//a[@class='linkConsultaSG btn btn-secondary btn-space'])")

) {

cdProcesso <- r1 |>
httr::content() |>
xml2::xml_find_first("//a[@class='linkConsultaSG btn btn-secondary btn-space']") |>
xml2::xml_attr("href") |>
httr::content() |>
xml2::xml_find_first("//a[@class='linkConsultaSG btn btn-secondary btn-space']") |>
xml2::xml_attr("href") |>
stringr::str_extract("(?<=Sg.)\\w+")
url2 <- paste0("https://esaj.tjsp.jus.br/cposg/show.do?processo.codigo=",cdProcesso, "&gateway=true")

url2 <- paste0("https://esaj.tjsp.jus.br/cposg/show.do?processo.codigo=",cdProcesso, "&gateway=true")


r2 <- httr::GET(url2)

url3 <- paste0("https://esaj.tjsp.jus.br/cposg/verificarAcessoPastaDigital.do?cdProcesso=",cdProcesso,"&conversationId=&_=1599440192646")



arquivo <- file.path(diretorio, paste0("tabela_cd_processo_pg_", .x, "_cd_processo_sg_",cdProcesso,".html"))


} else{

url3 <- paste0("https://esaj.tjsp.jus.br/cpopg/abrirPastaDigital.do?processo.codigo=",.x)
arquivo <- file.path(diretorio,paste0("tabela_cd_processo__pg",.x,".html"))

arquivo <- file.path(diretorio,paste0("tabela_cd_processo_pg_",.x,".html"))


}

url3|>
httr::GET() |>
httr::content("text") |>
httr::GET(httr::write_disk(arquivo,overwrite = TRUE))

}, NULL))

}


46 changes: 23 additions & 23 deletions R/tjsp_ler_tabela_docs_cd_processo.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,60 @@
#' @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_pg <- stringr::str_extract(.x,"(?<=processo_pg_)\\w+?(?=_)")

cd_processo_pg <- stringr::str_extract(.x,"(?<=processo_pg_)[A-Z0-9]+")
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_pg, .before =1) |>
tibble::add_column(cd_processo_sg, .after = 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 d527146

Please sign in to comment.