Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forcast5 not returning 5 day forcast #86

Open
vendion opened this issue Jun 15, 2020 · 2 comments
Open

Forcast5 not returning 5 day forcast #86

vendion opened this issue Jun 15, 2020 · 2 comments

Comments

@vendion
Copy link

vendion commented Jun 15, 2020

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?
@donseba
Copy link

donseba commented Sep 1, 2020

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

@vendion
Copy link
Author

vendion commented Sep 9, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants