diff --git a/backend/__init__.py b/backend/__init__.py index 530e5570..d46a06fb 100644 --- a/backend/__init__.py +++ b/backend/__init__.py @@ -151,13 +151,16 @@ def changedetection_app(config=None, datastore_o=None): return render_template("scrub.html") - @app.route("/edit", methods=['GET', 'POST']) - def edit_page(): + @app.route("/edit/", methods=['GET', 'POST']) + def edit_page(uuid): global messages import validators + # More for testing, possible to return the first/only + if uuid == 'first': + uuid = list(datastore.data['watching'].keys()).pop() + if request.method == 'POST': - uuid = request.args.get('uuid') url = request.form.get('url').strip() tag = request.form.get('tag').strip() @@ -172,10 +175,27 @@ def changedetection_app(config=None, datastore_o=None): if len(parts) == 2: extra_headers.update({parts[0].strip(): parts[1].strip()}) + update_obj = {'url': url, + 'tag': tag, + 'headers': extra_headers + } + + # Ignore text + form_ignore_text = request.form.get('ignore-text').strip() + ignore_text = [] + if form_ignore_text: + for text in form_ignore_text.split("\n"): + text = text.strip() + if len(text): + ignore_text.append(text) + + # Reset the previous_md5 so we process a new snapshot including stripping ignore text. + update_obj['previous_md5'] = "" + + update_obj['ignore_text'] = ignore_text + validators.url(url) # @todo switch to prop/attr/observer - datastore.data['watching'][uuid].update({'url': url, - 'tag': tag, - 'headers': extra_headers}) + datastore.data['watching'][uuid].update(update_obj) datastore.needs_write = True messages.append({'class': 'ok', 'message': 'Updated watch.'}) @@ -183,8 +203,6 @@ def changedetection_app(config=None, datastore_o=None): return redirect(url_for('index')) else: - - uuid = request.args.get('uuid') output = render_template("edit.html", uuid=uuid, watch=datastore.data['watching'][uuid], messages=messages) return output diff --git a/backend/fetch_site_status.py b/backend/fetch_site_status.py index c3e557e0..5c0d98ef 100644 --- a/backend/fetch_site_status.py +++ b/backend/fetch_site_status.py @@ -11,6 +11,15 @@ class perform_site_check(): super().__init__(*args, **kwargs) self.datastore = datastore + def strip_ignore_text(self, content, list_ignore_text): + + output=[] + for line in content.splitlines(): + if not any(skip_text in line for skip_text in list_ignore_text): + output.append(line) + + return "\n".join(output) + def run(self, uuid): timestamp = int(time.time()) # used for storage etc too stripped_text_from_html = False @@ -76,7 +85,16 @@ class perform_site_check(): if not len(r.text): update_obj["last_error"] = "Empty reply" - fetched_md5 = hashlib.md5(stripped_text_from_html.encode('utf-8')).hexdigest() + content = stripped_text_from_html.encode('utf-8') + + # If there's text to skip + # @todo we could abstract out the get_text() to handle this cleaner + if len(self.datastore.data['watching'][uuid]['ignore_text']): + content = self.strip_ignore_text(content, self.datastore.data['watching'][uuid]['ignore_text']) + + fetched_md5 = hashlib.md5(content).hexdigest() + + # could be None or False depending on JSON type if self.datastore.data['watching'][uuid]['previous_md5'] != fetched_md5: diff --git a/backend/pytest.ini b/backend/pytest.ini index 8b9ccf85..7716524b 100644 --- a/backend/pytest.ini +++ b/backend/pytest.ini @@ -1,2 +1,4 @@ [pytest] -addopts = --no-start-live-server --live-server-port=5005 \ No newline at end of file +addopts = --no-start-live-server --live-server-port=5005 +live_server_scope = function + diff --git a/backend/store.py b/backend/store.py index d36f4b25..b5e936ec 100644 --- a/backend/store.py +++ b/backend/store.py @@ -53,7 +53,8 @@ class ChangeDetectionStore: 'previous_md5': "", 'uuid': str(uuid_builder.uuid4()), 'headers': {}, # Extra headers to send - 'history': {} # Dict of timestamp and output stripped filename + 'history': {}, # Dict of timestamp and output stripped filename + 'ignore_text': [] # List of text to ignore when calculating the comparison checksum } if path.isfile('/source.txt'): diff --git a/backend/templates/edit.html b/backend/templates/edit.html index 89c2bfd6..525d3b27 100644 --- a/backend/templates/edit.html +++ b/backend/templates/edit.html @@ -18,10 +18,26 @@ Grouping tags, can be a comma separated list. + +
+ + + + Each line will be processed separately as an ignore rule. + +
+ +
-