kopia lustrzana https://github.com/dgtlmoon/changedetection.io
Option to attach screenshot to notification (#1127)
rodzic
d0d191a7d1
commit
f066a1c38f
|
@ -375,6 +375,7 @@ class watchForm(commonSettingsForm):
|
||||||
'Send a notification when the filter can no longer be found on the page', default=False)
|
'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_muted = BooleanField('Notifications Muted / Off', default=False)
|
||||||
|
notification_screenshot = BooleanField('Attach screenshot to notification (where possible)', default=False)
|
||||||
|
|
||||||
def validate(self, **kwargs):
|
def validate(self, **kwargs):
|
||||||
if not super().validate():
|
if not super().validate():
|
||||||
|
|
|
@ -38,6 +38,7 @@ class model(dict):
|
||||||
'notification_format': default_notification_format_for_watch,
|
'notification_format': default_notification_format_for_watch,
|
||||||
'notification_muted': False,
|
'notification_muted': False,
|
||||||
'notification_title': None,
|
'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)
|
'notification_urls': [], # List of URLs to add to the notification Queue (Usually AppRise)
|
||||||
'paused': False,
|
'paused': False,
|
||||||
'previous_md5': False,
|
'previous_md5': False,
|
||||||
|
|
|
@ -101,7 +101,10 @@ def process_notification(n_object, datastore):
|
||||||
apobj.notify(
|
apobj.notify(
|
||||||
title=n_title,
|
title=n_title,
|
||||||
body=n_body,
|
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()
|
apobj.clear()
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,9 @@ User-Agent: wonderbra 1.0") }}
|
||||||
<div class="pure-control-group inline-radio">
|
<div class="pure-control-group inline-radio">
|
||||||
{{ render_checkbox_field(form.notification_muted) }}
|
{{ render_checkbox_field(form.notification_muted) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="pure-control-group inline-radio">
|
||||||
|
{{ render_checkbox_field(form.notification_screenshot) }}
|
||||||
|
</div>
|
||||||
<div class="field-group" id="notification-field-group">
|
<div class="field-group" id="notification-field-group">
|
||||||
{% if has_default_notification_urls %}
|
{% if has_default_notification_urls %}
|
||||||
<div class="inline-warning">
|
<div class="inline-warning">
|
||||||
|
|
|
@ -3,7 +3,9 @@ import time
|
||||||
import re
|
import re
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from . util import set_original_response, set_modified_response, set_more_modified_response, live_server_setup
|
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 logging
|
||||||
|
import base64
|
||||||
|
|
||||||
from changedetectionio.notification import (
|
from changedetectionio.notification import (
|
||||||
default_notification_body,
|
default_notification_body,
|
||||||
|
@ -68,6 +70,14 @@ def test_check_notification(client, live_server):
|
||||||
# Give the thread time to pick up the first version
|
# Give the thread time to pick up the first version
|
||||||
time.sleep(3)
|
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
|
# Goto the edit page, add our ignore text
|
||||||
# Add our URL to the import page
|
# Add our URL to the import page
|
||||||
|
|
||||||
|
@ -86,6 +96,7 @@ def test_check_notification(client, live_server):
|
||||||
"Diff: {diff}\n"
|
"Diff: {diff}\n"
|
||||||
"Diff Full: {diff_full}\n"
|
"Diff Full: {diff_full}\n"
|
||||||
":-)",
|
":-)",
|
||||||
|
"notification_screenshot": True,
|
||||||
"notification_format": "Text"}
|
"notification_format": "Text"}
|
||||||
|
|
||||||
notification_form_data.update({
|
notification_form_data.update({
|
||||||
|
@ -142,6 +153,7 @@ def test_check_notification(client, live_server):
|
||||||
assert "preview/" in notification_submission
|
assert "preview/" in notification_submission
|
||||||
assert ":-)" in notification_submission
|
assert ":-)" in notification_submission
|
||||||
assert "New ChangeDetection.io Notification - {}".format(test_url) in notification_submission
|
assert "New ChangeDetection.io Notification - {}".format(test_url) in notification_submission
|
||||||
|
assert testimage in notification_submission
|
||||||
|
|
||||||
if env_base_url:
|
if env_base_url:
|
||||||
# Re #65 - did we see our BASE_URl ?
|
# Re #65 - did we see our BASE_URl ?
|
||||||
|
|
|
@ -74,6 +74,7 @@ class update_worker(threading.Thread):
|
||||||
n_object.update({
|
n_object.update({
|
||||||
'watch_url': watch['url'],
|
'watch_url': watch['url'],
|
||||||
'uuid': watch_uuid,
|
'uuid': watch_uuid,
|
||||||
|
'screenshot': watch.get_screenshot() if watch.get('notification_screenshot') else False,
|
||||||
'current_snapshot': snapshot_contents.decode('utf-8'),
|
'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': 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)
|
'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:
|
if 'notification_urls' in n_object:
|
||||||
n_object.update({
|
n_object.update({
|
||||||
'watch_url': watch['url'],
|
'watch_url': watch['url'],
|
||||||
'uuid': watch_uuid
|
'uuid': watch_uuid,
|
||||||
|
'screenshot': False
|
||||||
})
|
})
|
||||||
self.notification_q.put(n_object)
|
self.notification_q.put(n_object)
|
||||||
print("Sent filter not found notification for {}".format(watch_uuid))
|
print("Sent filter not found notification for {}".format(watch_uuid))
|
||||||
|
|
Ładowanie…
Reference in New Issue