Skip to content

Instantly share code, notes, and snippets.

@RamiKrispin
Created February 26, 2020 13:04
Show Gist options
  • Save RamiKrispin/09dfc404b0d519791494418c60a53d5c to your computer and use it in GitHub Desktop.
Save RamiKrispin/09dfc404b0d519791494418c60a53d5c to your computer and use it in GitHub Desktop.
`%>%` <- 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()
@RamiKrispin
Copy link
Author

You need to install jq:
https://stedolan.github.io/jq/download/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment