-
Notifications
You must be signed in to change notification settings - Fork 3
/
kmk_scrap.R
39 lines (27 loc) · 941 Bytes
/
kmk_scrap.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
library(rvest)
library(purrr)
scrap_kmk <- function() {
# Scrapping the data
link <- "https://www.kmk.org/dokumentation-statistik/statistik/schulstatistik/schulstatistische-informationen-zur-covid-19-pandemie.html"
xlsx_files <- read_html(link) %>%
html_nodes("a") %>%
html_attr("href") %>%
grep("xlsx", ., value = TRUE) %>%
paste0("https://www.kmk.org", .)
current_files <- xlsx_files %>% basename()
downloaded_files <- list.files("data_raw/kmk.org/")
new_files <- setdiff(current_files, downloaded_files)
if (length(new_files)>0) {
print("Downloading new file(s)...")
new_download <- grep(new_files, xlsx_files, value = TRUE)
# Downloading the data
map(new_download, function(x)
download.file(
x,
destfile = paste0("data_raw/kmk.org/", basename(x)),
mode = "wb"
))
} else {
print("No new data available.")
}
}