openweathermap icon indicating copy to clipboard operation
openweathermap copied to clipboard

Forcast5 not returning 5 day forcast

Open vendion opened this issue 4 years ago • 2 comments

Using the example provided in the repo requesting forcast data only returns 5 3 hour forcast datapoints rather than 5 days worth of data points.

go run ./weather.go -w Chattanooga -u f -l en -t forcast
Weather Forecast for Chattanooga:
Date & Time: 2020-06-15 18:00:00 +0000 UTC
Conditions:  Clouds scattered clouds
Temp:        75.43 
High:        78.39 
Low:         75.43

Date & Time: 2020-06-15 21:00:00 +0000 UTC
Conditions:  Clouds broken clouds
Temp:        75.7 
High:        76.55 
Low:         75.7

Date & Time: 2020-06-16 00:00:00 +0000 UTC
Conditions:  Clouds scattered clouds
Temp:        71.44 
High:        71.44 
Low:         71.37

Date & Time: 2020-06-16 03:00:00 +0000 UTC
Conditions:  Clear clear sky
Temp:        61.21 
High:        61.21 
Low:         61.12

Date & Time: 2020-06-16 06:00:00 +0000 UTC
Conditions:  Clear clear sky
Temp:        58.37 
High:        58.37 
Low:         58.37
```i
Is there a way to actually get the full 3 hour x 5 day dataset rather than just the next 15 hours?

vendion avatar Jun 15 '20 15:06 vendion

According to the documentation it is : 5 day forecast includes weather data every 3 hours

so changing this :

func getForecast5(location, units, lang string) (*owm.Forecast5WeatherData, error) {
	w, err := owm.NewForecast("5", units, lang, os.Getenv("OWM_API_KEY"))
	if err != nil {
		return nil, err
	}
	w.DailyByName(location, 5)
	forecast := w.ForecastWeatherJson.(*owm.Forecast5WeatherData)
	return forecast, err
}

to

func getForecast5(location, units, lang string) (*owm.Forecast5WeatherData, error) {
	w, err := owm.NewForecast("5", units, lang, os.Getenv("OWM_API_KEY"))
	if err != nil {
		return nil, err
	}
	w.DailyByName(location, 99)
	forecast := w.ForecastWeatherJson.(*owm.Forecast5WeatherData)
	return forecast, err
}

note the 99 , this way there is no limit. since we get 7(or 8?) reports a day * 5 days , so 35 - 40 results.

You could loop over these results and only take the ones at a given timestamp.

so yes naming is a bit confusing but it can do what it has to do

donseba avatar Sep 01 '20 20:09 donseba

Yes that does indeed work and I meant to add that passing a value other than 5 to DailyByName and the other similar functions does work, just the naming of that parameter is awkward due to how OWM's API functions.

If this is not a concern then this ticket can be closed.

vendion avatar Sep 09 '20 19:09 vendion