Skip to content

Commit 7c38d32

Browse files
committed
placed timezone in proper location
1 parent 6c14a81 commit 7c38d32

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

main.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"strconv"
1111
"time"
1212

13-
_ "time/tzdata" // Add this line to embed the IANA Time Zone database
13+
_ "time/tzdata" // Embed the IANA Time Zone database
1414
)
1515

1616
var (
17-
version = "0.0.16"
18-
debug bool // Add this line for the debug flag
17+
version = "0.0.17"
18+
debug bool
1919
)
2020

2121
type Response []struct {
@@ -39,11 +39,8 @@ func pushToInflux(t time.Time) {
3939
endOfDay := time.Now().Truncate(24 * time.Hour).Add(24*time.Hour - 1*time.Second)
4040
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"
4141

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-
4542
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)).
4744
Get(url)
4845

4946
if err != nil {
@@ -59,18 +56,12 @@ func pushToInflux(t time.Time) {
5956

6057
if debug {
6158
fmt.Printf("URL: %s\n", url)
62-
fmt.Println(result) // Print the result for debugging
59+
fmt.Println(result)
6360
} else {
6461
influxClient := influxdb2.NewClient(os.Getenv("INFLUXDB_URL"), os.Getenv("INFLUXDB_TOKEN"))
6562
writeAPI := influxClient.WriteAPIBlocking(os.Getenv("INFLUXDB_ORG"), os.Getenv("INFLUXDB_BUCKET"))
6663
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)
7465
if error != nil {
7566
fmt.Println(error)
7667
return
@@ -88,8 +79,15 @@ func pushToInflux(t time.Time) {
8879
}
8980

9081
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+
9189
intervalStr := os.Getenv("INTERVAL")
92-
interval := 1800 // Default interval in seconds
90+
interval := 1800
9391
if intervalStr != "" {
9492
intervalInt, err := strconv.Atoi(intervalStr)
9593
if err == nil {

0 commit comments

Comments
 (0)