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

Automatically detect latest flight data available #13

Closed
rafapereirabr opened this issue Jan 31, 2022 · 1 comment
Closed

Automatically detect latest flight data available #13

rafapereirabr opened this issue Jan 31, 2022 · 1 comment

Comments

@rafapereirabr
Copy link
Member

ANAC adds new flight data sets to their website almost every month. Ideally, we would like to automatically detect the latest flight data available . There should be a way to list the files on ANAC url using curl or httr. Any help / contributions / suggestions would be much appreciated!

@rafapereirabr
Copy link
Member Author

This function should do the trick of determining all dates available for flights data

#' Retrieve from ANAC website all dates available for flights data
#'
#' @return Numeric vector.
#' @keywords internal
#' @examples \dontrun{ if (interactive()) {
#' # check dates
#' a <- get_all_dates_available()
#'}}
get_all_dates_available <- function() {

  # read html table
  url = 'https://www.gov.br/anac/pt-br/assuntos/regulados/empresas-aereas/envio-de-informacoes/microdados/'
  h <- rvest::read_html(url)
  elements <- rvest::html_elements(h, "a")

  # filter elements of basica data
  basica_urls <- elements[elements %like% '/basica']
  basica_urls <- lapply(X=basica_urls, FUN=function(i){rvest::html_attr(i,"href")})

  # get all dates available
  all_dates <- substr(basica_urls, (nchar(basica_urls) + 1) -11, nchar(basica_urls)-4 )
  all_dates <- gsub("[-]", "", all_dates)
  all_dates <- as.numeric(all_dates)
  return(all_dates)
}

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