File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Vattenfall to InfluxDB exporter
2
2
3
- This is a simple exporter that scrapes the Vattenfall API and exports the prices to InfluxDB. It fetches the prices for the previous 24h and next 24h.
3
+ This is a simple exporter that scrapes the Vattenfall API and exports the prices to InfluxDB. It fetches the prices for the previous 24h and next 24h.
4
4
5
5
6
6
## Usage with Docker compose
@@ -37,6 +37,7 @@ services:
37
37
INFLUXDB_TOKEN : ' some_password'
38
38
INFLUXDB_BUCKET : ' elprice'
39
39
INFLUXDB_ORG : ' iot'
40
+ PRICE_AREA : ' SN3'
40
41
` ` `
41
42
42
43
Then you add InfluxDB as a datasource in Grafana(choose Flux as query language):
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import (
14
14
)
15
15
16
16
var (
17
- version = "0.0.18 "
17
+ version = "0.0.19 "
18
18
debug bool
19
19
)
20
20
@@ -36,11 +36,24 @@ func doEvery(d time.Duration, f func(time.Time)) {
36
36
func pushToInflux (t time.Time ) {
37
37
client := resty .New ()
38
38
39
+ // Read the PRICE_AREA environment variable, default to "SN3" if not set
40
+ priceArea := os .Getenv ("PRICE_AREA" )
41
+ if priceArea == "" {
42
+ fmt .Println ("Error: PRICE_AREA environment variable is not set" )
43
+ os .Exit (1 )
44
+ }
45
+
39
46
endOfDay := time .Now ().Truncate (24 * time .Hour ).Add (24 * time .Hour - 1 * time .Second )
40
- url := "https://www.vattenfall.se/api/price/spot/pricearea/" + time .Now ().Format ("2006-01-02" ) + "/" + endOfDay .AddDate (0 , 0 , 1 ).Format ("2006-01-02" ) + "/SN3"
47
+ url := fmt .Sprintf ("https://www.vattenfall.se/api/price/spot/pricearea/%s/%s/%s?_=%d" ,
48
+ time .Now ().Format ("2006-01-02" ),
49
+ endOfDay .AddDate (0 , 0 , 1 ).Format ("2006-01-02" ),
50
+ priceArea ,
51
+ time .Now ().UnixNano ()) // UnixNano returns a unique number
41
52
42
53
resp , err := client .R ().
43
54
SetHeader ("User-Agent" , fmt .Sprintf ("vattenfall-to-influxdb/%s (+https://github.com/rvoitenko/vattenfall-to-influxdb)" , version )).
55
+ SetHeader ("Cache-Control" , "no-cache, no-store, must-revalidate" ).
56
+ SetHeader ("Pragma" , "no-cache" ).
44
57
Get (url )
45
58
46
59
if err != nil {
You can’t perform that action at this time.
0 commit comments