From 35e93bbe59d0605c8a1a1e8b72799e300e8e0898 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 3 Oct 2022 18:10:05 +0000 Subject: [PATCH] implemented notify filter --- scraping.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scraping.go b/scraping.go index ce9f394..cc61474 100644 --- a/scraping.go +++ b/scraping.go @@ -3,6 +3,7 @@ package main import ( "bytes" "fmt" + "html/template" "io/ioutil" "log" "math" @@ -111,6 +112,10 @@ func getFilterResult(filter *Filter, db *gorm.DB, urlCache map[string]string, us { storeFilterResult(filter, db) } + case filter.Type == "notify": + { + notifyFilter(filter, db) + } case filter.Type == "condition": { switch filter.Var1 { @@ -698,5 +703,25 @@ func getFilterResultConditionHigherThan(filter *Filter) { } func notifyFilter(filter *Filter, db *gorm.DB) { + tmpl, err := template.New("test").Parse(filter.Var1) + if err != nil { + filter.log("Could not parse template: ", err) + return + } + dataMap := make(map[string]any, 20) + for _, parent := range filter.Parents { + dataMap[parent.Name] = html.UnescapeString(strings.Join(parent.Results, ", ")) + } + + id := filter.WatchID + + var watch Watch + db.Model(&Watch{}).First(&watch, id) + dataMap["Watch"] = watch + + var buffer bytes.Buffer + tmpl.Execute(&buffer, dataMap) + + log.Print(buffer.String()) }