Rework to use API instead of CSVs

This commit is contained in:
Daniel Mason 2022-01-02 12:01:59 +13:00
parent b73a6b7cae
commit 4937ec7253
13 changed files with 290 additions and 675 deletions

View file

@ -2,6 +2,7 @@ package nzcovidbot
import (
"fmt"
"net/url"
"strings"
"github.com/ashwanthkumar/slack-go-webhook"
@ -10,6 +11,7 @@ import (
// Slack webhook#channel
var SlackWebhooks []string
// Send slack request
func postToSlack() {
if len(SlackWebhooks) == 0 {
return
@ -40,3 +42,36 @@ func postToSlack() {
}
}
}
// Adds new rows to a slice for slack
func getPostableSlackData() []slack.Attachment {
rows := make([]slack.Attachment, 0)
if len(newLocations.Items) == 0 {
return rows
}
for _, item := range newLocations.Items {
rows = append(rows, getSlackRow(item))
}
return rows
}
// getSlackRow - Get slack attachment row
func getSlackRow(item ApiItem) slack.Attachment {
url := getMapsLinkFromAddress(item.EventName, item.Location.Address)
dateRange := item.getDateString()
attachment := slack.Attachment{
Title: &item.EventName,
TitleLink: &url,
Text: &dateRange,
}
return attachment
}
// getMapsLinkFromAddress hyperlink gmaps
func getMapsLinkFromAddress(name string, address string) string {
return fmt.Sprintf("https://www.google.com/maps/search/?api=1&query=%s", url.QueryEscape(name+", "+address))
}