-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmet_data.R
60 lines (50 loc) · 1.66 KB
/
met_data.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
# # # # # # # # # # # # # # # # # # # # # # # # # #
# Script to fetch meteorological data from INMET #
# # # # # # # # # # # # # # # # # # # # # # # # # #
# See https://github.com/lhmet/inmetr
# for install instructions
library(inmetr)
# Set YOUR working dir
setwd("C:/Users/vitor/OneDrive/Desktop")
# Create folder to store data
if (!dir.exists("./data")) {
mkdir("./data")
}
# Int vec ranging all station rows
stations_rows <- pmatch(bdmep_meta$name, bdmep_meta$name)
# Set date range
start_date <- "01/08/2019"
end_date <- "31/08/2019"
# # If it fails (it will), note down which idxs failed
# # and redo the `for` iterating only through missing vals
# missing_vals <- c(1,2,3)
# # If idxs [1, 2, 3] failed, for example
# for (i in missing_vals) {
# # Remember to comment out the original for!!
# Iter over all stations
for (i in stations_rows) {
# Placeholder for curr id to be downloaded
dl_id = bdmep_meta[i, "id"]
# Test if file already exists (if running multiple times)
if (!file.exists(paste("./data/", dl_id, ".csv", sep = "", collapse = NULL))) {
# Print working idx
cat("\n", "i =", i)
tryCatch({
# Import func
met_data <- bdmep_import(id = dl_id,
sdate = start_date,
edate = end_date,
email = "EMAIL",
passwd = "PASSWD",
destdir = "./data",
verbose = TRUE
)
},
error = function(cond) {
message(cond)
},
warning = function(cond) {
message(cond)
})
}
}