implemented notify filter
This commit is contained in:
parent
bc97a0947c
commit
35e93bbe59
1 changed files with 25 additions and 0 deletions
25
scraping.go
25
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())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue