Created
February 26, 2020 13:04
-
-
Save RamiKrispin/09dfc404b0d519791494418c60a53d5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`%>%` <- magrittr::`%>%` | |
dates_seq <- seq.Date(from = as.Date("2018-11-24"), to = as.Date("2018-11-30"), by = "day") | |
df <- lapply(dates_seq, function(i){ | |
cmd <- paste("curl -X GET https://api.carbonintensity.org.uk/intensity/", i, | |
"T00:00Z/", i, | |
"T23:30Z | jq --raw-output '.data[] | [.from, .intensity.actual] | @tsv'", | |
sep = "") | |
df <- data.table::fread(cmd = cmd, col.names = c("date_time_temp", "value")) | |
df[, date_time := lubridate::ymd_hm(date_time_temp, tz = "UTC")] | |
df <- df[, list(date_time, value)] | |
return(df) | |
}) %>% | |
data.table::rbindlist() | |
head(df) | |
df %>% TSstudio::ts_plot() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to install
jq
:https://stedolan.github.io/jq/download/