From 43365bd5d8b55e5f490ee96d5b631521735a3ed8 Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Sat, 18 Jun 2022 06:19:41 -0400 Subject: weather: update `NewWeather` Add handling to skip duplicate alerts. --- nws/nws.go | 1 + version/version.go | 2 +- weather/weather.go | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nws/nws.go b/nws/nws.go index ecef792..0a456d9 100644 --- a/nws/nws.go +++ b/nws/nws.go @@ -68,6 +68,7 @@ type FeatureProperties struct { } type Feature struct { + Id string Properties FeatureProperties } diff --git a/version/version.go b/version/version.go index 5c048e5..c10a5e0 100644 --- a/version/version.go +++ b/version/version.go @@ -4,4 +4,4 @@ // Peach version. package version -const Version = "0.5.0" +const Version = "0.5.1.dev" diff --git a/weather/weather.go b/weather/weather.go index e001255..7b7161a 100644 --- a/weather/weather.go +++ b/weather/weather.go @@ -121,7 +121,11 @@ func NewWeather(lat, lng float32) (*Weather, error, int) { // Add alerts if they exist. if len(fBundle.Alerts.Features) > 0 { w.Alerts = make([]Alert, 0) + am := make(map[string]bool, 0) // Alerts map. for _, f := range fBundle.Alerts.Features { + if _, ok := am[f.Id]; ok { + continue // Duplicate; skip. + } a := Alert{ Event: f.Properties.Event, Severity: f.Properties.Severity, @@ -129,6 +133,7 @@ func NewWeather(lat, lng float32) (*Weather, error, int) { Instruction: strings.Split(f.Properties.Instruction, "\n\n"), } w.Alerts = append(w.Alerts, a) + am[f.Id] = true } } return w, nil, 200 -- cgit v1.2.3