From 68ef980920082c743b8f33e6c1d95cd7c6f69fad Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sun, 7 Aug 2022 15:14:54 -0400 Subject: weather: add `humidity` --- weather/weather.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'weather') diff --git a/weather/weather.go b/weather/weather.go index 7b7161a..3a2f9f8 100644 --- a/weather/weather.go +++ b/weather/weather.go @@ -10,6 +10,7 @@ import ( "ricketyspace.net/peach/nws" "ricketyspace.net/peach/photon" + t "ricketyspace.net/peach/time" "ricketyspace.net/peach/version" ) @@ -138,3 +139,19 @@ func NewWeather(lat, lng float32) (*Weather, error, int) { } return w, nil, 200 } + +func humidity(g *nws.ForecastGrid) (int, error) { + if g == nil { + return 0, fmt.Errorf("humdity: forecast grid data empty") + } + for _, v := range g.Properties.RelativeHumidity.Values { + yes, err := t.IsCurrent(v.ValidTime) + if err != nil { + return 0, fmt.Errorf("humidity: %v", err) + } + if yes { + return v.Value, nil + } + } + return 0, fmt.Errorf("humidity: not found") +} -- cgit v1.2.3