From 8423c83f2cbadaeebc8a3dac994ed490b4364b55 Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Sun, 16 Jan 2022 14:36:39 +1300 Subject: [PATCH] Append omicron to name if contained in description --- CHANGELOG.md | 3 +++ internal/nzcovidbot/api.go | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f2c6b2..eadbe83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +# 1.3 +- Omicron related ones will post with an asterisk to indicate + ## 1.2 - Change lastUpdated to pointer reference and use built in .After() functions - Change date format to support multiple dates in single point of interest diff --git a/internal/nzcovidbot/api.go b/internal/nzcovidbot/api.go index 472597f..bf9e2f2 100644 --- a/internal/nzcovidbot/api.go +++ b/internal/nzcovidbot/api.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "sort" + "strings" "time" ) @@ -56,7 +57,7 @@ func fetchAPILocations() (ApiResponse, error) { } // Set user-agent info - req.Header.Set("User-Agent", "NZCovidBot/1.2 (https://m2.nz)") + req.Header.Set("User-Agent", "NZCovidBot/1.3 (https://m2.nz)") // Fire off the request resp, err := client.Do(req) @@ -95,7 +96,17 @@ func getNewAPILocations() { // Iterate over the data and only find new locations for _, item := range locations.Items { - if item.PublishedAt.After(previousUpdatedTime) { + if strings.Contains(strings.ToLower(item.PublicAdvice), "omicron") { + copy := item + // Apend Omicron if Omicron in advice + copy.EventName = copy.EventName + " (Omicron)" + newItems[item.Location.City] = append(newItems[item.Location.City], copy) + + // Always keep the latest + if item.PublishedAt.After(newUpdatedTime) { + newUpdatedTime = item.PublishedAt + } + } else if item.PublishedAt.After(previousUpdatedTime) { // Clone the item to put in our own lil slice copy := item newItems[item.Location.City] = append(newItems[item.Location.City], copy)