improve channel name

This commit is contained in:
cato-001 2025-07-07 18:01:22 +02:00
parent 94c0cdde24
commit b68b341862
2 changed files with 15 additions and 13 deletions

13
main.go
View file

@ -20,10 +20,11 @@ func main() {
}
parser.MustParse(os.Args[1:])
NotifyChannel = fmt.Sprintf("%s-%d", args.Street, args.Home)
streetNumbers, err := GetStreetNumbers()
if err != nil {
fmt.Println(err)
_ = SendErr(args.Street, err)
_ = SendErr(err)
return
}
@ -34,8 +35,7 @@ func main() {
tomorrow, err := AwlTomorrow(streetNumber, args.Home)
if err != nil {
fmt.Println(err)
_ = SendErr(args.Street, err)
_ = SendErr(err)
return
}
@ -43,10 +43,9 @@ func main() {
return
}
err = SendAwlNotification(args.Street, tomorrow)
err = SendAwlNotification(tomorrow)
if err != nil {
fmt.Println(err)
_ = SendErr(args.Street, err)
_ = SendErr(err)
return
}
}

15
ntfy.go
View file

@ -6,7 +6,9 @@ import (
"strings"
)
func SendAwlNotification(channel string, binColors []string) error {
var NotifyChannel string
func SendAwlNotification(binColors []string) error {
var bins = make([]string, 0, 5)
for _, color := range binColors {
switch color {
@ -30,17 +32,18 @@ func SendAwlNotification(channel string, binColors []string) error {
message = "Morgen werden folgende Tonnen abgeholt: "
}
message += strings.Join(bins, ", ")
return SendNotification(channel, message)
return SendNotification(message)
}
func SendNotification(channel, message string) error {
topic := fmt.Sprintf("https://ntfy.sh/awl_neuss_%s", channel)
func SendNotification(message string) error {
topic := fmt.Sprintf("https://ntfy.sh/awl-neuss-%s", NotifyChannel)
_, err := http.Post(topic, "text/plain", strings.NewReader(message))
return err
}
func SendErr(channel string, err error) error {
topic := fmt.Sprintf("https://ntfy.sh/awl_neuss_%s_err", channel)
func SendErr(err error) error {
fmt.Println(err)
topic := fmt.Sprintf("https://ntfy.sh/awl-neuss-%s-err", NotifyChannel)
_, err = http.Post(topic, "text/plain", strings.NewReader(err.Error()))
return err
}