andrekos andrekos - 2 months ago 9x
R Question

extracting Australia BOM weather data programmatically with R

Here I can enter a substation number, say 009572; choose the variable (say Temperature) and its type (say Maximum). Clicking "get data" brings me to a page with a link "All years of data". Click it, and you got a zip file. I am aware of this questions, but here I don't have a direct link to a zip file. Can something be done to automate weather data extraction from the Australian Bureau Of Meteorology website with R?


Here's the code that I have done to download instantly and it also resolves your p_c problem. You can improve the function if you want and post.

#daily code = 136
#monthy code = 139

bomdata<- function(station,code){
for(i in 1: length(station)){
p.url<-paste("",station[i],"&p_display_type=availableYears&p_nccObsCode=",code,sep ="")
filelist <- list.files(pattern = ".txt")
foo<- file(filelist,"r")
text<- suppressWarnings(readLines(foo))
l<- regexpr(":",text[1])
m<- unlist(gregexpr(",", text[1], perl = TRUE))
pc<- substr(text[1],l[[1]]+1,l[[1]]+(m[2]-(l[[1]]+1)))
url<-paste("",station[i],"&p_c=",pc,"&p_nccObsCode=",code,"&p_startYear=2013", sep ="")
suppressWarnings(download.file(url,paste(station[i],".zip",sep= ""), mode = "wb"))