@@ -10,12 +10,12 @@ import (
10
10
"strconv"
11
11
"time"
12
12
13
- _ "time/tzdata" // Add this line to embed the IANA Time Zone database
13
+ _ "time/tzdata" // Embed the IANA Time Zone database
14
14
)
15
15
16
16
var (
17
- version = "0.0.16 "
18
- debug bool // Add this line for the debug flag
17
+ version = "0.0.17 "
18
+ debug bool
19
19
)
20
20
21
21
type Response []struct {
@@ -39,11 +39,8 @@ func pushToInflux(t time.Time) {
39
39
endOfDay := time .Now ().Truncate (24 * time .Hour ).Add (24 * time .Hour - 1 * time .Second )
40
40
url := "https://www.vattenfall.se/api/price/spot/pricearea/" + time .Now ().Format ("2006-01-02" ) + "/" + endOfDay .AddDate (0 , 0 , 2 ).Format ("2006-01-02" ) + "/SN3"
41
41
42
- // Set the custom user agent
43
- userAgent := "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
44
-
45
42
resp , err := client .R ().
46
- SetHeader ("User-Agent" , userAgent ).
43
+ SetHeader ("User-Agent" , fmt . Sprintf ( "vattenfall-to-influxdb/%s (+https://github.com/rvoitenko/vattenfall-to-influxdb)" , version ) ).
47
44
Get (url )
48
45
49
46
if err != nil {
@@ -59,18 +56,12 @@ func pushToInflux(t time.Time) {
59
56
60
57
if debug {
61
58
fmt .Printf ("URL: %s\n " , url )
62
- fmt .Println (result ) // Print the result for debugging
59
+ fmt .Println (result )
63
60
} else {
64
61
influxClient := influxdb2 .NewClient (os .Getenv ("INFLUXDB_URL" ), os .Getenv ("INFLUXDB_TOKEN" ))
65
62
writeAPI := influxClient .WriteAPIBlocking (os .Getenv ("INFLUXDB_ORG" ), os .Getenv ("INFLUXDB_BUCKET" ))
66
63
for _ , rec := range result {
67
- location , locErr := time .LoadLocation ("Europe/Stockholm" )
68
- if locErr != nil {
69
- fmt .Println (locErr )
70
- return
71
- }
72
-
73
- date , error := time .ParseInLocation ("2006-01-02T15:04:05" , rec .TimeStamp , location )
64
+ date , error := time .Parse ("2006-01-02T15:04:05" , rec .TimeStamp )
74
65
if error != nil {
75
66
fmt .Println (error )
76
67
return
@@ -88,8 +79,15 @@ func pushToInflux(t time.Time) {
88
79
}
89
80
90
81
func main () {
82
+ location , err := time .LoadLocation ("Europe/Stockholm" )
83
+ if err != nil {
84
+ fmt .Println ("Error loading location 'Europe/Stockholm':" , err )
85
+ os .Exit (1 )
86
+ }
87
+ time .Local = location
88
+
91
89
intervalStr := os .Getenv ("INTERVAL" )
92
- interval := 1800 // Default interval in seconds
90
+ interval := 1800
93
91
if intervalStr != "" {
94
92
intervalInt , err := strconv .Atoi (intervalStr )
95
93
if err == nil {
0 commit comments