data-raw/nivo_observations_history.R

#' Retrieve and parse nivological observations
#'
#' We request historical observations given by Meteo France from automatic stations located in the mountains.
#'
#' @return tibble
request_nivo_observations_history <- function() {
  start_year <- 2009
  end_year <- 2021
  winter_months <- formatC(c(1:5, 12), width = 2, flag = 0)

  url_base <- "https://donneespubliques.meteofrance.fr/donnees_libres/Txt/Nivo/Archive/nivo"
  url_suffix <- "csv.gz"

  urls <- list()
  for (i in start_year:end_year) {
    for (j in winter_months) {
      if (i == start_year && j != "12") {
        next
      }
      if (i == end_year && j == "12") {
        break
      }
      urls[[length(urls)+1]] <- paste(url_base, paste0(i, j), url_suffix, sep = ".")
    }
  }

  request_nivo_observations(urls)
}

#' Get and save nivo observations data
#'
#' @return
use_nivo_observations_history <- function() {
  nivo_observations_history <- request_nivo_observations_history()
  usethis::use_data(nivo_observations_history, overwrite = TRUE)
}
vadmbertr/bonski.data documentation built on Dec. 23, 2021, 2:06 p.m.