From 27c8454350b467dd4413231caca66f364e014ff4 Mon Sep 17 00:00:00 2001 From: Lasse Bjerre Date: Sun, 27 Jun 2021 21:39:44 +0200 Subject: [PATCH] Trim spaces + option to ignore empty --- config.example.json | 3 ++- monitor/monitor.go | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config.example.json b/config.example.json index 2f0b2cb..2236cf6 100644 --- a/config.example.json +++ b/config.example.json @@ -12,7 +12,8 @@ "type": "css", "paths": ["#content > dl > dt:nth-child(3)", "#content > dl > dt:nth-child(5)"] }, - "filters": ["perfection", "success"] + "filters": ["perfection", "success"], + "ignoreEmpty": true } ], "notifiers": { diff --git a/monitor/monitor.go b/monitor/monitor.go index 1ad7161..c3e91cb 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -59,6 +59,7 @@ type Monitor struct { Interval time.Duration `json:"interval"` Selector Selector `json:"selector,omitempty"` Filters Filters `json:"filters,omitempty"` + IgnoreEmpty bool `json:"ignoreEmpty,omitempty"` notifierService NotifierService started bool doneChannel chan bool @@ -226,6 +227,11 @@ func (m *Monitor) check() { return } + if m.IgnoreEmpty && processedContent == "" { + log.Print("Content is empty, ignoring...") + return + } + storageContent := m.storage.GetContent(m.id) if compareContent(storageContent, processedContent) { @@ -266,7 +272,7 @@ func processContent(content io.ReadCloser, selector Selector, filters Filters) ( selectorContent = processFilters(filters, selectorContent) } - return selectorContent, nil + return strings.TrimSpace(selectorContent), nil } func processFilters(filters Filters, content string) string {