From 83565787aed3f4f772d1ea69b8c707ef128f84ba Mon Sep 17 00:00:00 2001 From: bwees Date: Mon, 11 Jul 2022 20:35:30 -0400 Subject: [PATCH] added logic for filtering based on diff attributes --- changedetectionio/fetch_site_status.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/changedetectionio/fetch_site_status.py b/changedetectionio/fetch_site_status.py index 6c3dbec89..db6f534ea 100644 --- a/changedetectionio/fetch_site_status.py +++ b/changedetectionio/fetch_site_status.py @@ -4,6 +4,7 @@ import os import re import time import urllib3 +import difflib from changedetectionio import content_fetcher, html_tools @@ -276,11 +277,29 @@ class perform_site_check(): else: logging.debug("check_unique_lines: UUID {} had unique content".format(uuid)) + diff_filters = { + "add": watch.get('trigger_on_add', True), + "del": watch.get('trigger_on_del', True), + "modify": watch.get('trigger_on_modify', True) + } + + if False in diff_filters.values(): # if we are supposed to filter any diff types + print(">>>>>>>>>>>> Filtering diffs") + # get the diff types present in the watch + diff_types = watch.get_diff_types(str(stripped_text_from_html)) + + # for each diff type, if the filter setting is false, and the diff type is present, then set the changed_detected to false + for diff_type in diff_types: + if not diff_filters[diff_type] and diff_types[diff_type]: + changed_detected = False + break # we only need to check one diff type + # Always record the new checksum update_obj["previous_md5"] = fetched_md5 # On the first run of a site, watch['previous_md5'] will be None, set it the current one. if not watch.get('previous_md5'): watch['previous_md5'] = fetched_md5 + watch['previous_text'] = str(stripped_text_from_html) return changed_detected, update_obj, text_content_before_ignored_filter, fetcher.screenshot, fetcher.xpath_data