Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix needed to override blocker #6

Open
ivanhanigan opened this issue Jul 20, 2023 · 0 comments
Open

Fix needed to override blocker #6

ivanhanigan opened this issue Jul 20, 2023 · 0 comments

Comments

@ivanhanigan
Copy link
Member

I found that this flag is needed wget --user-agent="Mozilla"

get_data_v2 <- function (
  variable_in = as.character(variable[,1])
  , 
  measure = as.character(variable[, 2])
  , 
  timestep = as.character(variable[,3])
  , 
  startdate = as.POSIXct(sdate)
  , 
  enddate = as.POSIXct(edate)
  ) 
{
if(timestep == "month" | timestep == "monthly"){
  if(variable_in == 'temperature'){
    url = "http://www.bom.gov.au/web03/ncc/www/awap/{variable}/{measure}/{timestep}/grid/0.05/history/nat/{startdate}{enddate}.grid.Z"
    timestep <- "month"
  } else {
    url = "http://www.bom.gov.au/web03/ncc/www/agcd/{variable}/{measure}/{timestep}/grid/0.05/history/nat/{startdate}{enddate}.grid.zip"
  }
} else {
  url = "http://www.bom.gov.au/web03/ncc/www/awap/{variable}/{measure}/{timestep}/grid/0.05/history/nat/{startdate}{enddate}.grid.Z"
}
  url = gsub("{variable}", variable_in, url, fixed = TRUE)
  url = gsub("{measure}", measure, url, fixed = TRUE)
  url = gsub("{timestep}", timestep, url, fixed = TRUE)
  url = gsub("{startdate}", gsub("-", "", startdate), url, fixed = TRUE)
  url = gsub("{enddate}", gsub("-","",enddate), url, fixed = TRUE)
  ##try(download.file(url, sprintf("%s_%s%s.grid.Z", measure, 
  ##                               startdate, enddate), mode = "wb"))
  system(paste0('wget --user-agent="Mozilla" ', url))
  
  ## rename temperature grid.zip
  if(variable_in == 'temperature'){
    fnames <- dir(pattern = paste0(enddate,".grid.Z"))
    for(fname in fnames){
      ## fname = fnames[1]
      file.rename(fname, file.path(dirname(fname),paste0(measure,"_", basename(fname))))
    }
    measure
  }
  ## rename rainfall grid.zip
  if(variable_in == 'rainfall'){
    fnames <- dir(pattern = paste0(enddate,".grid.zip"))
    for(fname in fnames){
      ## fname = fnames[1]
      file.rename(fname, file.path(dirname(fname),paste0(measure,"_", basename(fname))))
    }
    measure
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant