diff --git a/R/getAllFromCoord.R b/R/getAllFromCoord.R new file mode 100644 index 0000000..70ecf7a --- /dev/null +++ b/R/getAllFromCoord.R @@ -0,0 +1,42 @@ +# Define function +getAllFromCoord <- function(coord, start_date, end_date, allstations, N = 3, headers, base = "https://public-api.meteofrance.fr",btw_station_sleep = 1, within_statio_sleep=5,endpoint="public/DPClim/v1/") { + three_station = getIdFromCoords(coord, allstations, N = N) + alldata = lapply(three_station$Id_station, function(statid) { + print(paste("recuperer station", statid)) + allstat = tryCatch( + getStationData(start_date = start_date, end_date = end_date, station_id = statid, headers = headers, base = base, timesleep=within_statio_sleep,dpclim=endpoint), + error = function(e) {print(e); NULL} + ) + print(paste("done, sleep",btw_station_sleep,"sec")) + print(dim(allstat)) + Sys.sleep(btw_station_sleep) + return(allstat) + }) + + alldata = do.call("rbind.data.frame", alldata) + ids = three_station$Nom_usuel + names(ids) = three_station$Id_station + cbind.data.frame(alldata, Nom_usuel = ids[as.character(alldata[,1])]) +} + +# Define function +getAllFromCoordDPObs <- function(coord, start_date, end_date, allstations, N = 3, headers, base = "https://public-api.meteofrance.fr",btw_station_sleep = 1, within_statio_sleep=5,endpoint="public/DPClim/v1/") { + three_station = getIdFromCoords(coord, allstations, N = N) + alldata = lapply(three_station$Id_station, function(statid) { + print(paste("recuperer station", statid)) + allstat = tryCatch( + getStationDataDPObs(start_date = start_date, end_date = end_date, station_id = statid, headers = headers, base = base, timesleep=within_statio_sleep,dpclim=endpoint), + error = function(e) {print(e); NULL} + ) + print(paste("done, sleep",btw_station_sleep,"sec")) + print(dim(allstat)) + Sys.sleep(btw_station_sleep) + return(allstat) + }) + + alldata = do.call("rbind.data.frame", alldata) + ids = three_station$Nom_usuel + names(ids) = three_station$Id_station + cbind.data.frame(alldata, Nom_usuel = ids[as.character(alldata[,1])]) +} +