forked from marcellofilgueiras/trf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpopg_precatorios.r
119 lines (77 loc) · 3.39 KB
/
cpopg_precatorios.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Precatórios
# Autor: Marcello Silveira Filgueiras
library(tidyverse)
library(httr)
library(xml2)
library(rvest)
#Lista de Julgados
adufb_processos_raw <- readxl::read_excel("cpopg/data_raw/adufb_processos.xlsx",
skip = 3)
adufb_processos_tidy <- adufb_processos_raw %>%
janitor::clean_names() %>%
tidyr::fill(c(qtd, processo_execucao, situacao),
.direction = "down")%>%
tidyr::drop_na() %>%
mutate(across(.cols = c(qtd:precatorio_rpv),
.fns = stringr::str_squish))
processos_precatorios_ind <- adufb_processos_tidy %>%
pull(processo_precatorio_rpv)
processos_precatorios_exemplo <- c( "0331616-40.2020.4.05.0000" ,
"0313610-82.2020.4.05.0000",
"0313609-97.2020.4.05.0000")
# Baixando e Iterando -----------------------------------------------------
trf5_baixar_cpopg <- function(processos = "",
diretorio= "") {
url_base <- "https://cp.trf5.jus.br/processo/"
barra_progresso <- progress::progress_bar $ new(total = length(processos))
map (.x= processos,
.f= ~ {
barra_progresso$tick()
httr::GET (paste0(url_base,
.x),
httr::write_disk(path = paste0(diretorio,
"/",
"julgados_",
as.character(.x),
"_",
Sys.time()%>%
stringr::str_replace_all("\\D","_"),
".html")
)
) }
)
}
#trf5_baixar_cpopg(processos = processos_precatorios_ind,
# diretorio = "cpopg/data_raw")
trf5_ler_cpopg <- function(diretorio= "") {
# Faça a lista de Arquivos presente na pasta
arquivos_lista <- base::list.files(paste0(diretorio,"/"),
pattern = "\\.html$",
full.names = TRUE)
#Faça o tamanho da barra de progresso
barra_progresso <- progress::progress_bar $ new(total =
length(arquivos_lista)
)
#Leia os Arquivos e Parseia
purrr::map( .x= arquivos_lista,
.f = ~{
barra_progresso$tick()
arquivos_raw <- xml2::read_html (.x)
processo <- arquivos_raw %>%
xml2::xml_find_first("/html/body/p[2]") %>%
xml2::xml_text() %>%
stringr::str_remove("\n PROCESSO Nº ")
precatorio<- arquivos_raw %>%
xml2::xml_find_first("/html/body/table") %>%
xml2::xml_find_all("./tr/td") %>% xml_text()
#tibble::as_tibble(processo
#, precatorio
# )
list(processo,
precatorio)
})
}
trf5_ler_cpopg(diretorio = "cpopg/data_raw")
a<- trf5_ler_cpopg(diretorio = "cpopg/data_raw")
map(a,pluck())
as_tibble()