Fix up api logic

This commit is contained in:
Daniel Mason 2022-01-16 14:49:19 +13:00
parent 51163b15e6
commit df5d74bd64

View file

@ -34,7 +34,7 @@ type ApiItem struct {
PublicAdvice string `json:"publicAdvice"` PublicAdvice string `json:"publicAdvice"`
VisibleInWebform bool `json:"visibleInWebform"` VisibleInWebform bool `json:"visibleInWebform"`
PublishedAt time.Time `json:"publishedAt"` PublishedAt time.Time `json:"publishedAt"`
UpdatedAt interface{} `json:"updatedAt"` UpdatedAt time.Time `json:"updatedAt"`
ExposureType string `json:"exposureType"` ExposureType string `json:"exposureType"`
Location struct { Location struct {
Latitude string `json:"latitude"` Latitude string `json:"latitude"`
@ -96,21 +96,29 @@ func getNewAPILocations() {
// Iterate over the data and only find new locations // Iterate over the data and only find new locations
for _, item := range locations.Items { for _, item := range locations.Items {
if strings.Contains(strings.ToLower(item.PublicAdvice), "omicron") { if item.PublishedAt.After(previousUpdatedTime) {
copy := item
// Apend Omicron if Omicron in advice
copy.EventName = copy.EventName + " (Omicron)"
newItems[item.Location.City] = append(newItems[item.Location.City], copy)
} else if item.PublishedAt.After(previousUpdatedTime) {
// Clone the item to put in our own lil slice // Clone the item to put in our own lil slice
copy := item copy := item
newItems[item.Location.City] = append(newItems[item.Location.City], copy) newItems[item.Location.City] = append(newItems[item.Location.City], copy)
}
// Always keep the latest // Always keep the latest
if item.PublishedAt.After(newUpdatedTime) { if item.PublishedAt.After(newUpdatedTime) {
newUpdatedTime = item.PublishedAt newUpdatedTime = item.PublishedAt
} }
} else if item.UpdatedAt.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.UpdatedAt.After(newUpdatedTime) {
newUpdatedTime = item.UpdatedAt
}
}
}
} }
// Make sure to clear out the previous list and append new data in a map based on location // Make sure to clear out the previous list and append new data in a map based on location