Algum tempo atrás o Alisson Lucrecio e o Éder Comunello estavam trabalhando em um tópico sobre obtenção de dados do INMET.
Como precisei obter alguns dados hoje, resolvi testar o código, que por sinal funcionou perfeitamente.
Como os dados são salvos em formato ```.html```, tentei montar um script organizar os dados em um ```data.frame```, assim como deixar apenas uma linha para cada dia de coletado, pois os dados do originais do INMET tem formato de duas linhas para cada dia de coleta.
obs: a função que ordena os dias é não tem uma boa performance, pois faz um bom tempo que fiz ela.
#=================================================================
# Rafael Tieppo
# rafaelt@unemat.br
# http://docente.unemat.br/rafaeltieppo/
# 29-08-2016
#=================================================================
##### Goal 1
### Script to sign in - INMET
### Historical Data
### Original Source:
### http://r-br.2285057.n4.nabble.com/R-br-r-baixando-dados-inmet-td4660459.html
### http://r-br.2285057.n4.nabble.com/R-br-RCurl-td4659610.html
##### Goal 2
### Ordering and filtering DATA from INMET
### use oneline() function from
#************************************************************
#************************************************************
# GOAL 1
#************************************************************
#************************************************************
#------------------------------------------------------------
### Packages
library(RCurl)
library(bitops)
#------------------------------------------------------------
#------------------------------------------------------------
### Logging INMET
### Login link
myURL1 <- "http://www.inmet.gov.br/projetos/rede/pesquisa/inicio.php"
### Data link
myURL2 <- "http://www.inmet.gov.br/projetos/rede/pesquisa/gera_serie_txt.php?&mRelEstacao=83309&btnProcesso=serie&mRelDtInicio=01/01/2015&mRelDtFim=29/08/2016&mAtributos=,,1,1,,,,,,1,1,,1,1,1,1,"
#------------------------------------------------------------
#------------------------------------------------------------
### Access Data
myParams=list(
mCod="EMAIL", ### alterar!
mSenha="PASSWORD", ### alterar!
btnProcesso = " Acessar ")
#------------------------------------------------------------
#------------------------------------------------------------
### Getting Data
myCurl <- getCurlHandle()
curlSetOpt(cookiejar="cookies.txt", useragent="Chrome/10.0.648.133" , followlocation=TRUE, curl=myCurl)
###"Mozilla/5.0"
login <- postForm(myURL1, .params=myParams, curl=myCurl)
DATA <- getURLContent(myURL2, curl=myCurl)
#------------------------------------------------------------
#************************************************************
#************************************************************
# GOAL 2
#************************************************************
#************************************************************
#------------------------------------------------------------
### Tiding Data
### Using shell script to separate DATA from text
#### grep "^83309" < ESTACAO_83309.html > ESTACAO_83303_DATA.csv
### Shell script, get all lines that starts with "83309" (station number)
SHELL_FUN = paste("grep", "^83309", "<", "ESTACAO_83309.html",
">", "ESTACAO_83303_DATA.csv",
sep = ' ')
###
system(SHELL_FUN)
DATA_83303 <- read.csv("ESTACAO_83303_DATA.csv", sep = ";", dec = ".")
colnames(DATA_83303) <- c("Estacao", "Data", "Hora", "Precipitacao",
"TempMaxima", "TempMinima", "Insolacao",
"Evaporacao_Piche", "Temp_Comp_Media",
"UR_Media", "Vel_Vent_Media")
names(DATA_83303)
#------------------------------------------------------------
#------------------------------------------------------------
### Organizing DATA
### Data from INMET has two lines for each
### To put one line for each day, use oneline() function
### Calling ONE_LINE function
### from https://github.com/rafatieppo/INMET_DATA_ORDER
### ATTENTION
### To use oneline() is mandatory a data.frame with a specific cols data
### order, as follow (names doen not matter, only sequence):
### Estacao; Data; Hora; Precipitacao; TempMaxima; TempMinima;
### Insolacao; Umidade Relativa Media; Velocidade do Vento Media;
DATA_83303 <- DATA_83303[c(1:7,10:11)]
Estacao;Data;Hora;Precipitacao;TempMaxima;TempMinima;Insolacao;Evaporacao
Piche;Temp Comp Media;Umidade Relativa Media;Velocidade do Vento Media;
### Ordering with oneline() function
DATA_83303_one_line <- one_line(DATA_83303)
edit(DATA_83303_one_line)
#------------------------------------------------------------