From 1c3c38b61421af576a31e809201f6f5ce3f45cf2 Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Mon, 8 Aug 2022 19:48:10 +0000 Subject: [PATCH] in between commit --- models.go | 2 +- scraping.go | 17 +++++++++++------ templates/editGroup.html | 30 +++++++++++++----------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/models.go b/models.go index acde5de..8416b65 100644 --- a/models.go +++ b/models.go @@ -34,7 +34,7 @@ type Filter struct { FilterGroupID uint `form:"filter_group_id" yaml:"filter_group_id" binding:"required"` FilterGroup *FilterGroup Name string `form:"filter_name" yaml:"filter_name" binding:"required" validate:"min=1"` - Type string `form:"filter_type" yaml:"filter_type" binding:"required" validate:"oneof=replace regex substring"` + Type string `form:"filter_type" yaml:"filter_type" binding:"required" validate:"oneof=xpath css replace match substring"` From string `form:"from" yaml:"from" binding:"required"` To string `form:"to" yaml:"to" binding:"required"` } diff --git a/scraping.go b/scraping.go index 0498f9d..7698f05 100644 --- a/scraping.go +++ b/scraping.go @@ -55,7 +55,7 @@ func getFilterResult(s string, filter *Filter, newStrings *[]string) { } case filter.Type == "regex": { - getFilterResultRegex(s, filter, newStrings) + getFilterResultMatch(s, filter, newStrings) } case filter.Type == "substring": { @@ -99,16 +99,21 @@ func getFilterResultCSS(s string, filter *Filter, newStrings *[]string) { } func getFilterResultReplace(s string, filter *Filter, newStrings *[]string) { - *newStrings = append(*newStrings, strings.ReplaceAll(s, filter.From, filter.To)) -} - -func getFilterResultRegex(s string, filter *Filter, newStrings *[]string) { regex, err := regexp.Compile(filter.From) if err != nil { log.Print(err) return } - *newStrings = append(*newStrings, regex.ReplaceAllString(s, filter.To)) + *newStrings = append(*newStrings, regex.ReplaceAllString(filter.From, filter.To)) +} + +func getFilterResultMatch(s string, filter *Filter, newStrings *[]string) { + r, err := regexp.Compile(filter.From) + if err != nil { + log.Print(err) + return + } + *newStrings = append(*newStrings, r.ReplaceAllString(s, filter.To)) } func getFilterResultSubstring(s string, filter *Filter, newStrings *[]string) { diff --git a/templates/editGroup.html b/templates/editGroup.html index 329358d..ba642fb 100644 --- a/templates/editGroup.html +++ b/templates/editGroup.html @@ -116,7 +116,6 @@
- +
- +
-
+
- + +
@@ -210,10 +210,6 @@
- -
- -
@@ -268,7 +264,7 @@
- +
- +
-
+
- +
@@ -351,11 +347,11 @@
- +
- +