Skip to content

Commit

Permalink
Use numer of days
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Pereira committed Sep 9, 2024
1 parent 311d698 commit 2c128ec
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion backends/open-meteo.com.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,21 @@ func (opmeteo *openmeteoConfig) Fetch(location string, numdays int) iface.Data {
var params []string
var loc string

if numdays <= 0 {
log.Fatal("Number of days less than 1 ")
}

if matched, err := regexp.MatchString(`^-?[0-9]*(\.[0-9]+)?,-?[0-9]*(\.[0-9]+)?$`, location); matched && err == nil {
s := strings.Split(location, ",")
loc = fmt.Sprintf("latitude=%s&longitude=%s", s[0], s[1])
}
if len(location) > 0 {
params = append(params, loc)
}
params = append(params, "current=temperature_2m,apparent_temperature,is_day,weather_code&hourly=temperature_2m,apparent_temperature,weather_code,wind_direction_10m&daily=weather_code,temperature_2m_max,apparent_temperature_max,sunrise,sunset&timeformat=unixtime&forecast_days=3")
params = append(params, "current=temperature_2m,apparent_temperature,is_day,weather_code,wind_direction_10m")
params = append(params, "hourly=temperature_2m,apparent_temperature,weather_code,wind_direction_10m")
params = append(params, "daily=weather_code,temperature_2m_max,apparent_temperature_max,sunrise,sunset")
params = append(params, fmt.Sprintf("timeformat=unixtime&forecast_days=%d", numdays))

requri := openmeteoURI + strings.Join(params, "&")

Expand Down

0 comments on commit 2c128ec

Please sign in to comment.