Revisión | eca957feb5186614e1c95812655e3fc0d1d1f5b9 (tree) |
---|---|
Tiempo | 2024-09-27 02:53:18 |
Autor | Lorenzo Isella <lorenzo.isella@gmai...> |
Commiter | Lorenzo Isella |
Now I input the period and the code automatically retrieves the number of records and the number of pages to download.
@@ -7,25 +7,60 @@ | ||
7 | 7 | |
8 | 8 | source("/home/lorenzo/myprojects-hg/R-codes/stat_lib.R") |
9 | 9 | |
10 | +## NB: I have 628,468 records of SA awards for ES in the year 2022 | |
11 | + | |
12 | + | |
13 | +ini <- "01/01/2022" ##initial time dd/mm/yyyy | |
14 | +fin <- "31/12/2022" | |
15 | + | |
10 | 16 | ## url <- "https://www.infosubvenciones.es/bdnstrans/api/ayudasestado/busqueda?page=0&pageSize=10000&order=numeroConvocatoria&direccion=asc&vpd=GE&fechaDesde=01%2F01%2F2019&fechaHasta=31%2F12%2F2022" |
11 | 17 | |
18 | +ini2 <- transform_date_url(ini) | |
19 | +fin2 <- transform_date_url(fin) | |
20 | + | |
21 | + | |
12 | 22 | options(timeout=120) |
13 | 23 | |
14 | 24 | url1 <- "https://www.infosubvenciones.es/bdnstrans/api/ayudasestado/busqueda?page=" |
15 | 25 | |
16 | 26 | |
17 | 27 | |
18 | -url2 <- "&pageSize=10000&order=numeroConvocatoria&direccion=asc&vpd=GE&fechaDesde=01%2F01%2F2019&fechaHasta=31%2F12%2F2022" | |
28 | +## url2 <- "&pageSize=10000&order=numeroConvocatoria&direccion=asc&vpd=GE&fechaDesde=01%2F01%2F2022&fechaHasta=31%2F12%2F2022" | |
29 | + | |
30 | +url2a <- "&pageSize=10000&order=numeroConvocatoria&direccion=asc&vpd=GE&fechaDesde" | |
31 | + | |
32 | + | |
33 | +url2b <- "&fechaHasta" | |
34 | + | |
35 | + | |
36 | +url_for_pages <- paste(url1, 0, url2a, ini2, url2b, fin2, sep="") | |
37 | + | |
38 | +data_for_pages <- fromJSON(url_for_pages) | |
39 | + | |
40 | +n_records <- data_for_pages$totalElements | |
41 | + | |
42 | +print("The total number of records is, ") | |
43 | +print(n_records) | |
44 | + | |
45 | +n_pages <- data_for_pages$totalPages | |
46 | + | |
47 | +print("and the total number of pages is, ") | |
48 | +print(n_pages) | |
49 | + | |
50 | +saveRDS(n_pages, "../input/number_pages.RDS") | |
19 | 51 | |
20 | 52 | remove_files_with_pattern("../input/data*RDS") |
21 | 53 | |
22 | -for (counter in 0:250){ | |
54 | +for (counter in 0:(n_pages-1)){ | |
23 | 55 | |
24 | 56 | print("counter is, ") |
25 | 57 | print(counter) |
26 | 58 | |
27 | - url <- paste(url1, counter, url2, sep="") | |
59 | + ## url <- paste(url1, counter, url2, sep="") | |
28 | 60 | |
61 | + url <- paste(url1, counter, url2a, ini2, url2b, fin2, sep="") | |
62 | + | |
63 | + | |
29 | 64 | mydata <- fromJSON(url) |
30 | 65 | |
31 | 66 |