diff --git a/cmd/camper-weather/main.go b/cmd/camper-weather/main.go index 824fcab..351c442 100644 --- a/cmd/camper-weather/main.go +++ b/cmd/camper-weather/main.go @@ -42,13 +42,16 @@ func main() { log.Fatal(err) } defer conn.Release() + updateForecast(context.Background(), conn) +} - if _, err := conn.Exec(context.Background(), "set role to admin"); err != nil { +func updateForecast(ctx context.Context, conn *database.Conn) { + if _, err := conn.Exec(ctx, "set role to admin"); err != nil { log.Fatal(err) } var stationURL string - if err := conn.QueryRow(context.Background(), ` + if err := conn.QueryRow(ctx, ` select station_uri from weather_forecast `).Scan( @@ -68,7 +71,7 @@ func main() { } for _, forecast := range result.Forecasts { - if _, err := db.Exec(context.Background(), ` + if _, err := conn.Exec(ctx, ` update weather_forecast set weather_condition_id = $1 , day_temperature = $2