-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcovid_downloads.R
29 lines (27 loc) · 1.24 KB
/
covid_downloads.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
library(here)
library(lubridate)
Sys.setlocale(category = "LC_ALL", locale = "en_CA.UTF-8")
source("_R/covid_datasets.R")
links <- links[c("local_sit_en", "local_sit_fr", "qc_sit_en", "qc_sit_fr")]
lapply(names(links), function(x) {
print(x)
xml2::download_html(links[[x]],
file = here("_websites", x, paste(format(now(), "%Y%m%d%H%M%S"), ".html", sep = "")))
})
file_connection <- file(here("_websites", "last_download_time.txt"))
writeLines(as.character(now()), file_connection)
close(file_connection)
csvs <- datasets[unlist(lapply(datasets, function(item) item$download_daily ))]
unique_number <- round(as.numeric(as.period(interval(as_datetime("1970-01-02 4:00:00", tz = "EST"), now())), "minutes"))
lapply(csvs, function(item) {
print(item$descr)
if(item$overwrite) {
download.file(paste(item$url, "?randNum=", unique_number, sep = ""),
cacheOK = FALSE,
destfile = here("_csv", item$path, paste(item$file_name, ".csv", sep = "")))
} else {
download.file(paste(item$url, "?randNum=", unique_number, sep = ""),
cacheOK = FALSE,
destfile = here("_csv", item$path, paste(item$file_name, "_", format(now(), "%Y-%m-%d-%H-%M-%S"), ".csv", sep = "")))
}
})