diff --git a/changedetectionio/forms.py b/changedetectionio/forms.py index 7f857d0c..2904f461 100644 --- a/changedetectionio/forms.py +++ b/changedetectionio/forms.py @@ -375,6 +375,7 @@ class watchForm(commonSettingsForm): 'Send a notification when the filter can no longer be found on the page', default=False) notification_muted = BooleanField('Notifications Muted / Off', default=False) + notification_screenshot = BooleanField('Attach screenshot to notification (where possible)', default=False) def validate(self, **kwargs): if not super().validate(): diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index a49fe069..3689cf93 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -38,6 +38,7 @@ class model(dict): 'notification_format': default_notification_format_for_watch, 'notification_muted': False, 'notification_title': None, + 'notification_screenshot': False, # Include the latest screenshot if available and supported by the apprise URL 'notification_urls': [], # List of URLs to add to the notification Queue (Usually AppRise) 'paused': False, 'previous_md5': False, diff --git a/changedetectionio/notification.py b/changedetectionio/notification.py index 55364fcd..116c0cce 100644 --- a/changedetectionio/notification.py +++ b/changedetectionio/notification.py @@ -101,7 +101,10 @@ def process_notification(n_object, datastore): apobj.notify( title=n_title, body=n_body, - body_format=n_format) + body_format=n_format, + # False is not an option for AppRise, must be type None + attach=None if not n_object.get('screenshot') else n_object.get('screenshot') + ) apobj.clear() diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index e7cd5b06..0f8e2ce1 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -141,6 +141,9 @@ User-Agent: wonderbra 1.0") }}
{{ render_checkbox_field(form.notification_muted) }}
+
+ {{ render_checkbox_field(form.notification_screenshot) }} +
{% if has_default_notification_urls %}
diff --git a/changedetectionio/tests/test_notification.py b/changedetectionio/tests/test_notification.py index 6b534f62..dbd0d26e 100644 --- a/changedetectionio/tests/test_notification.py +++ b/changedetectionio/tests/test_notification.py @@ -3,7 +3,9 @@ import time import re from flask import url_for from . util import set_original_response, set_modified_response, set_more_modified_response, live_server_setup +from . util import extract_UUID_from_client import logging +import base64 from changedetectionio.notification import ( default_notification_body, @@ -68,6 +70,14 @@ def test_check_notification(client, live_server): # Give the thread time to pick up the first version time.sleep(3) + testimage = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=' + # Write the last screenshot png + + uuid = extract_UUID_from_client(client) + datastore = 'test-datastore' + with open(os.path.join(datastore, str(uuid), 'last-screenshot.png'), 'wb') as f: + f.write(base64.b64decode(testimage)) + # Goto the edit page, add our ignore text # Add our URL to the import page @@ -86,6 +96,7 @@ def test_check_notification(client, live_server): "Diff: {diff}\n" "Diff Full: {diff_full}\n" ":-)", + "notification_screenshot": True, "notification_format": "Text"} notification_form_data.update({ @@ -142,6 +153,7 @@ def test_check_notification(client, live_server): assert "preview/" in notification_submission assert ":-)" in notification_submission assert "New ChangeDetection.io Notification - {}".format(test_url) in notification_submission + assert testimage in notification_submission if env_base_url: # Re #65 - did we see our BASE_URl ? diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index 564be402..154187b1 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -74,6 +74,7 @@ class update_worker(threading.Thread): n_object.update({ 'watch_url': watch['url'], 'uuid': watch_uuid, + 'screenshot': watch.get_screenshot() if watch.get('notification_screenshot') else False, 'current_snapshot': snapshot_contents.decode('utf-8'), 'diff': diff.render_diff(watch_history[dates[-2]], watch_history[dates[-1]], line_feed_sep=line_feed_sep), 'diff_full': diff.render_diff(watch_history[dates[-2]], watch_history[dates[-1]], True, line_feed_sep=line_feed_sep) @@ -106,7 +107,8 @@ class update_worker(threading.Thread): if 'notification_urls' in n_object: n_object.update({ 'watch_url': watch['url'], - 'uuid': watch_uuid + 'uuid': watch_uuid, + 'screenshot': False }) self.notification_q.put(n_object) print("Sent filter not found notification for {}".format(watch_uuid))