New notification tokens - watch_uuid, watch_title, watch_tag, (#201)

* New notification tokens ; Tokens added: watch_uuid, watch_title, watch_tag, updated settings description
pull/193/head^2
Minty 3 years ago committed by GitHub
parent f8937e437a
commit b9e0ad052f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -7,3 +7,4 @@ __pycache__
.pytest_cache
build
dist
.vscode/settings.json

@ -4,6 +4,9 @@ import apprise
valid_tokens = {
'base_url': '',
'watch_url': '',
'watch_uuid': '',
'watch_title': '',
'watch_tag': '',
'diff_url': '',
'preview_url': '',
'current_snapshot': ''
@ -22,7 +25,7 @@ def process_notification(n_object, datastore):
n_title = datastore.data['settings']['application']['notification_title']
# Insert variables into the notification content
notification_parameters = create_notification_parameters(n_object)
notification_parameters = create_notification_parameters(n_object, datastore)
raw_notification_text = [n_body, n_title]
parameterised_notification_text = dict(
@ -39,11 +42,19 @@ def process_notification(n_object, datastore):
# Notification title + body content parameters get created here.
def create_notification_parameters(n_object):
def create_notification_parameters(n_object, datastore):
from copy import deepcopy
# in the case we send a test notification from the main settings, there is no UUID.
uuid = n_object['uuid'] if 'uuid' in n_object else ''
if uuid != '':
watch_title = datastore.data['watching'][uuid]['title']
watch_tag = datastore.data['watching'][uuid]['tag']
else:
watch_title = 'Change Detection'
watch_tag = ''
# Create URLs to customise the notification with
base_url = os.getenv('BASE_URL', '').strip('"')
watch_url = n_object['watch_url']
@ -64,11 +75,12 @@ def create_notification_parameters(n_object):
{
'base_url': base_url,
'watch_url': watch_url,
'watch_uuid': uuid,
'watch_title': watch_title,
'watch_tag': watch_tag,
'diff_url': diff_url,
'preview_url': preview_url,
'current_snapshot': n_object['current_snapshot'] if 'current_snapshot' in n_object else ''
})
return tokens
return tokens

@ -82,6 +82,18 @@
<td><code>{watch_url}</code></td>
<td>The URL being watched.</td>
</tr>
<tr>
<td><code>{watch_uuid}</code></td>
<td>The UUID of the watch.</td>
</tr>
<tr>
<td><code>{watch_title}</code></td>
<td>The title of the watch.</td>
</tr>
<tr>
<td><code>{watch_tag}</code></td>
<td>The tag of the watch.</td>
</tr>
<tr>
<td><code>{preview_url}</code></td>
<td>The URL of the preview page generated by changedetection.io.</td>

@ -1,5 +1,6 @@
import os
import time
import re
from flask import url_for
from . util import set_original_response, set_modified_response, live_server_setup
@ -35,7 +36,8 @@ def test_check_notification(client, live_server):
url_for("edit_page", uuid="first"),
data={"notification_urls": notification_url,
"url": test_url,
"tag": "",
"tag": "my tag",
"title": "my title",
"headers": "",
"fetch_backend": "html_requests",
"trigger_check": "y"},
@ -100,6 +102,9 @@ def test_check_notification(client, live_server):
data={"notification_title": "New ChangeDetection.io Notification - {watch_url}",
"notification_body": "BASE URL: {base_url}\n"
"Watch URL: {watch_url}\n"
"Watch UUID: {watch_uuid}\n"
"Watch title: {watch_title}\n"
"Watch tag: {watch_tag}\n"
"Preview: {preview_url}\n"
"Diff URL: {diff_url}\n"
"Snapshot: {current_snapshot}\n"
@ -129,8 +134,9 @@ def test_check_notification(client, live_server):
with open("test-datastore/notification.txt", "r") as f:
notification_submission = f.read()
# @todo regex that diff/uuid-31123-123-etc
assert re.search('Watch UUID: [0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}', notification_submission, re.IGNORECASE)
assert "Watch title: my title" in notification_submission
assert "Watch tag: my tag" in notification_submission
assert "diff/" in notification_submission
assert "preview/" in notification_submission
assert ":-)" in notification_submission

Loading…
Cancel
Save