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
There is an error?
sh: jq: command not found
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 5379 100 5379 0 0 2730 0 0:00:01 0:00:01 --:--:-- 2730
(23) Failed writing body
Error in lapply(list(...), .num_to_date) :
object 'date_time_temp' not found
In addition: Warning messages:
1: In (if (.Platform$OS.type == "unix") system else shell)(paste0("(", :
error in running command
2: In data.table::fread(cmd = cmd, col.names = c("date_time_temp", :
Error in lapply(list(...), .num_to_date) :
object 'date_time_temp' not found