-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetfrost_meta.R
37 lines (27 loc) · 979 Bytes
/
getfrost_meta.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Function: get meta data for stations from frost.met.no
# Examples:
# Oslo Blindern and Bergen Florida: getfrost_meta("SN18700, SN50540")
# All stations: getfrost_meta("")
#
# 30 September 2020
#
# --------------------------------------------------------------
library(jsonlite)
library(tidyr)
library(readr)
source("err_messages.R")
# ------------------------------------------------------------
getfrost_meta <- function(station){
client_id <- as.character(read_tsv("client_id.txt", col_names = TRUE, cols(client_id = col_character())))
url <- paste0("https://", client_id, "@frost.met.no/sources/v0.jsonld?",
"ids=", station)
output <- try(fromJSON(URLencode(url), flatten = TRUE))
if (class(output) != 'try-error') {
print(paste0(station, ": metadata retrieved from frost.met.no! (", object.size(output), " bytes)"))
meta <- unnest(output$data, cols=c())
return(meta)
} else {
err_messages()
}
}