Compare commits

...

3 Commits
v1.1 ... main

Author SHA1 Message Date
1559b86429 added day filter example 2024-05-29 14:36:25 -04:00
32e6237680 Merge branch 'main' of https://git.oki.cx/dagger/bell-system 2024-02-29 11:57:47 -04:00
3662b458aa Filter Days 2024-02-29 11:57:44 -04:00
2 changed files with 38 additions and 23 deletions

View File

@ -22,6 +22,14 @@ times:
- "09:00:00"
- "09:40:00"
# Whitelisted days of the week (Format: Monday)
days:
- "Monday"
- "Tuesday"
- "Wednesday"
- "Thursday"
- "Friday"
# AXIS Horn Config
horn:
url: "https://horn-ip/axis-cgi/playclip.cgi?location=soundtoplay.mp3&repeat=0&volume=100&audiooutput=1"

13
main.go
View File

@ -16,6 +16,7 @@ import (
type config struct {
Horn map[string]string `yaml:"horn"`
Times []string `yaml:"times"`
Days []string `yaml:"days"`
}
func (config *config) getConf() *config {
@ -31,7 +32,7 @@ func (config *config) getConf() *config {
logger.Error("Unmarshal", logger.Args(":", err))
}
logger.Info("Config loaded", logger.Args("Times", config.Times, "API URL", config.Horn["url"]))
logger.Info("Config loaded", logger.Args("Times", config.Times, "Days", config.Days, "API URL", config.Horn["url"]))
return config
}
@ -47,7 +48,7 @@ func main() {
pterm.DefaultCenter.Println(s)
pterm.DefaultCenter.Println("By Cody (" + pterm.LightBlue("https://oki.cx/tree") + ")")
pterm.DefaultCenter.Println("v1.1")
pterm.DefaultCenter.Println("v1.2")
pterm.Print("\n")
@ -60,7 +61,10 @@ func main() {
for {
ctime := time.Now().Format("15:04:05")
cday := time.Now().Weekday()
for _, day := range config.Days {
if day == cday.String() {
for _, time := range config.Times {
if time == ctime {
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
@ -81,7 +85,10 @@ func main() {
if resp.StatusCode != 200 {
logger.Error(fmt.Sprintf("HTTP request failed: %s", resp.Status))
} else {
logger.Info(fmt.Sprintf("Sending HTTP request to %s", config.Horn["url"]), logger.Args("Reason", "Config File", "Time", ctime, "Status Code", resp.Status))
logger.Info(fmt.Sprintf("Sending HTTP request to %s", config.Horn["url"]),
logger.Args("Reason", "Config File", "Time", ctime, "Status Code", resp.Status))
}
}
}
}
}