#' List available locations for past 24 hour observations
#'
#' Requests locations from the met office API in xml format and returns a \code{tibble}
#' @export
#' @examples
#' observations_list_sites()
#' @importFrom magrittr %>%
observations_list_sites <- function() {
check_saved_api_key()
xml_data <- xml2::read_xml(paste0(
api_root(),
"val/wxobs/all/datatype/sitelist?res=daily",
"&key=",
read_api_key()
))
sites <- tibble::tibble(xml = rvest::xml_nodes(xml_data, "Location")) %>%
dplyr::mutate(locations = purrr::map(xml, .f = ~tibble::as.tibble(t(xml2::xml_attrs(.))))) %>%
dplyr::select(locations) %>%
tidyr::unnest(cols = c(locations)) %>%
dplyr::mutate_at(dplyr::vars(c("elevation", "latitude", "longitude")), as.numeric)
sites
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.