-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
44 lines (37 loc) · 969 Bytes
/
main.go
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
38
39
40
41
42
43
44
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"github.com/thegreenwebfoundation/grid-intensity-go/pkg/provider"
)
func main() {
// Register at https://api-portal.electricitymaps.com/
token := os.Getenv("ELECTRICITY_MAPS_API_TOKEN")
if token == "" {
log.Fatalln("please set the env variable `ELECTRICITY_MAPS_API_TOKEN`")
}
url := os.Getenv("ELECTRICITY_MAPS_API_URL")
if url != "" {
log.Fatalln("please set the env variable `ELECTRICITY_MAPS_API_URL`")
}
c := provider.ElectricityMapsConfig{
APIURL: url,
Token: token,
}
e, err := provider.NewElectricityMaps(c)
if err != nil {
log.Fatalln("could not make provider", err)
}
res, err := e.GetCarbonIntensity(context.Background(), "AU-SA")
if err != nil {
log.Fatalln("could not get carbon intensity", err)
}
bytes, err := json.MarshalIndent(res, "", "\t")
if err != nil {
log.Fatalln("could not get carbon intensity", err)
}
fmt.Println(string(bytes))
}