Skip to content

Commit

Permalink
feat(get_rv_gauges)
Browse files Browse the repository at this point in the history
fixes #25
  • Loading branch information
dimfalk committed Dec 27, 2024
1 parent 959cc75 commit 65a0da6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: NRWgauges
Title: Web-scraping gauge (meta-)data from various providers in NRW, Germany
Version: 0.3.5
Version: 0.3.6
Date: 2024-12-27
Authors@R:
person("Dimitri", "Falk", , "[email protected]", role = c("aut", "cre"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
export(get_eglv_gauges)
export(get_eglv_measurements)
export(get_eglv_meta)
export(get_rv_gauges)
export(get_rv_meta)
40 changes: 40 additions & 0 deletions R/get_rv_gauges.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Get RV gauge metadata (simplified), locations and latest measurements
#'
#' @return Sf object.
#' @export
#'
#' @examples
#' \dontrun{
#' get_rv_gauges()
#' }
get_rv_gauges <- function() {

# debugging ------------------------------------------------------------------

# check arguments ------------------------------------------------------------

# ----------------------------------------------------------------------------

base_url <- "https://www.talsperrenleitzentrale-ruhr.de/online-daten/gewaesserpegel/"

# query definition
query <- list("tx_onlinedata_gauges%5baction%5d" = "json",
"tx_onlinedata_gauges%5bcontroller%5d" = "Gauges",
"type" = "863")

# send request
r_raw <- httr::GET(base_url, query = query)

# parse response: raw to json
r_json <- httr::content(r_raw, "text", encoding = "UTF-8")

gauges <- jsonlite::fromJSON(r_json) |>
tibble::as_tibble()

# fix columns
gauges[["datetime"]] <- gauges[["datetime"]] |> as.POSIXct(tz = "etc/GMT-1")

gauges[["value"]] <- gauges[["value"]] |> as.numeric()

gauges
}
19 changes: 19 additions & 0 deletions man/get_rv_gauges.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 65a0da6

Please sign in to comment.