Option to attach screenshot to notification (#1127)

test-improvements
Matthias Bilger 2 years ago committed by GitHub
parent d0d191a7d1
commit f066a1c38f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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():

@ -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,

@ -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()

@ -141,6 +141,9 @@ User-Agent: wonderbra 1.0") }}
<div class="pure-control-group inline-radio">
{{ render_checkbox_field(form.notification_muted) }}
</div>
<div class="pure-control-group inline-radio">
{{ render_checkbox_field(form.notification_screenshot) }}
</div>
<div class="field-group" id="notification-field-group">
{% if has_default_notification_urls %}
<div class="inline-warning">

@ -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 ?

@ -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))

Loading…
Cancel
Save