Skip to content

Instantly share code, notes, and snippets.

@chrismcg
Created July 28, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcg/a69d4035bd21d238000802017f22ef62 to your computer and use it in GitHub Desktop.
Save chrismcg/a69d4035bd21d238000802017f22ef62 to your computer and use it in GitHub Desktop.
---
title: "Ireland Electricity"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(ghql)
library(jsonlite)
library(fpp3)
```
```{r}
con <- GraphqlClient$new(
url = "https://sg.chrismcg.com/api"
)
#con$load_schema()
query <- Query$new()
query$query('data', '
{
co2_emissions: timeseries(from:"2015-01-01T00:00:00Z", variable:CO2_EMISSIONS) {
data
region
variable {
name
unit
}
}
}
')
result <- query$queries$data %>%
con$exec() %>%
jsonlite::fromJSON()
co2_emissions <- result$data$co2_emissions$data %>%
as_tibble() %>%
rename(timestamp = V1, value = V2) %>%
mutate(timestamp = as_datetime(timestamp), variable = "CO2_EMISSIONS") %>%
as_tsibble(variable, timestamp)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment