library(jsonlite) library(httr) devtools::load_all() source("secrets") # Create a Bearer token header headers.default <- add_headers( accept = "*/*", apikey = token4 ) allstations=read.csv("allstations.csv") #get all station lacouch.coor <- c(45.3722971,5.6387118) vignass.coor=c(44.8550665,5.8441789) foreve=list() n_periods = 10 for (i in 0:(n_periods-1)) { enddate = format(Sys.Date() - i * 182, "%Y-%m-%d") # Approximately 6 months, adjust if you need more precision # Calculate start date for the period, 182 days before the end date startdate = format(Sys.Date() - (i * 182 + 181), "%Y-%m-%d") # Approximately 6 months foreve[[paste0("per",i)]]=tryCatch(getAllFromCoord(lacouch.coor,startdate,enddate,allstations,headers=headers.default,base="https://public-api.meteofrance.fr"),error=function(e)e) } startdate = format(Sys.Date() - 5, "%Y-%m-%d") test1=getAllFromCoord(vignass.coor,start_date=startdate,end_date= format(Sys.Date() , "%Y-%m-%d"),allstations,headers=headers.default) #test1=do.call("rbind.data.frame",foreve) #test1=read.csv("allvignass.csv")[,-1] cols=palette.colors()[1:length(unique(test1$Nom_usuel))] names(cols)=unique(test1$Nom_usuel) testsep=test1#[test1[,3]>0,] testsep[testsep[,3]==0,c(3,4)]=NA testsep=testsep[getDate(testsep[,2])>a,] plot(getDate(testsep[,2]),testsep[,3],pch=20,col=adjustcolor(cols[testsep$Nom_usuel],.4),cex=1.3,ylim=c(0,8)) legend("topleft",col=cols,legend=names(cols),pch=20,cex=2) abline(v=as.numeric(as.POSIXlt("2024-08-07",format="%Y-%m-%d")),lwd=3,col="red") #write.csv(file="allvignass.csv",test1)