summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth ravikumar <s@ricketyspace.net>2022-08-07 15:14:54 -0400
committersiddharth ravikumar <s@ricketyspace.net>2022-08-07 15:14:54 -0400
commit68ef980920082c743b8f33e6c1d95cd7c6f69fad (patch)
tree523610e11506b90519997051335377532455803a
parentd8d3a53f04373865197b411f283df728e6111314 (diff)
weather: add `humidity`
-rw-r--r--weather/weather.go17
1 files changed, 17 insertions, 0 deletions
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")
+}