Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
replace httr::GET() with httr::RETRY()
Browse files Browse the repository at this point in the history
  • Loading branch information
annnvv committed Apr 21, 2020
1 parent 409629f commit 59355dd
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/download_kml.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ download_kml <- function(locator) {

for(i in 1:length(to_download)) {
full_url <- paste(base_url, geo_ref, "kml", to_download[i], sep="/")
temp_file <- content(GET(url = full_url), as = "text")
temp_file <- content(RETRY(verb = "GET", url = full_url, terminate_on = c(404)), as = "text")
###Write file
to_write<- file(paste(my_path,to_download[i], ".kml", sep=""), open = "w")
writeLines(temp_file,to_write)
Expand Down
2 changes: 1 addition & 1 deletion R/get_climate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ get_climate_data <- function(locator,geo_type,type, cvar, start, end){

# print(full_url)

res <- GET(full_url)
res <- RETRY("GET", full_url, terminate_on = c(404))
stop_for_status(res)
raw_data <- try(content(res, as = "text"), silent = TRUE)
if(sum(grep("unexpected",raw_data)) > 0){
Expand Down
2 changes: 1 addition & 1 deletion R/get_ensemble_climate_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ get_ensemble_climate_data <- function(locator,
data_url <- paste(geo_type, type, "ensemble", cvar, start, end, locator, sep="/")
extension <- ".json"
full_url <- paste(base_url, data_url, extension, sep="")
raw_data <- try(content(GET(full_url), as="text"), silent=TRUE)
raw_data <- try(content(RETRY("GET", full_url, terminate_on = c(404)), as="text"), silent=TRUE)
data_out <- jsonlite::fromJSON(raw_data)
# json <- jsonlite::fromJSON(raw_data, FALSE)
# data_out <- plyr::rbind.fill(lapply(json, function(z) {
Expand Down
2 changes: 1 addition & 1 deletion R/get_historical_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if(geo_type == "basin"){
data_url <- paste(geo_type,"cru",cvar,time_scale,locator,sep="/")
extension <- ".json"
full_url <- paste(base_url,data_url,extension,sep="")
raw_data <- try(content(GET(full_url),as="text"),silent=T)
raw_data <- try(content(RETRY("GET", full_url, terminate_on = c(404)),as="text"),silent=T)

if(sum(grep("unexpected",raw_data)) > 0){
stop(paste("You entered a country for which there is no data. ",locator," is not a country with any data"))
Expand Down

0 comments on commit 59355dd

Please sign in to comment.