From e95be9ecd9fe7e8a0e0a9d0fcd2251dac10259a5 Mon Sep 17 00:00:00 2001 From: a3510377 Date: Mon, 30 Sep 2024 16:21:32 +0000 Subject: [PATCH] Refactor code to skip empty details and improve notifications for work and school closures --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 4a19474..513ea1d 100644 --- a/main.go +++ b/main.go @@ -82,17 +82,19 @@ func checkAndNotification() error { if len(notifications) > 0 { text := "" + sendNotifications := []WorkSchoolCloseData{} for _, v := range notifications { + if len(v.Details) == 0 { + continue + } + text += fmt.Sprintf("%s: \n %s\n", v.County, strings.Join(v.Details, "\n ")) - } - sendNotifications := []WorkSchoolCloseData{} - for _, data := range notifications { - if !areaNamesMap[data.County] || len(data.Details) == 0 { + if !areaNamesMap[v.County] { continue } - sendNotifications = append(sendNotifications, data) + sendNotifications = append(sendNotifications, v) } if len(sendNotifications) > 0 {