mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-09-17 02:45:53 +00:00
Adding ability to use a wrapping template "notification.html"
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built 📦 package works basically. (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been cancelled
ChangeDetection.io App Test / lint-code (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-10 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-11 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-12 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-13 (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built 📦 package works basically. (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been cancelled
ChangeDetection.io App Test / lint-code (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-10 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-11 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-12 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-13 (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
import os
|
||||
import time
|
||||
import apprise
|
||||
from loguru import logger
|
||||
@@ -84,6 +85,7 @@ def _populate_notification_tokens(n_object, datastore):
|
||||
'diff_removed': diff.render_diff(prev_snapshot, current_snapshot, include_added=False, line_feed_sep=line_feed_sep),
|
||||
'screenshot': watch.get_screenshot() if watch and watch.get('notification_screenshot') else None,
|
||||
'triggered_text': triggered_text,
|
||||
'watch_url_raw': watch.get('url'),
|
||||
'watch_url': watch_url,
|
||||
})
|
||||
|
||||
@@ -136,11 +138,30 @@ def process_notification(n_object, datastore):
|
||||
if not n_object.get('notification_urls'):
|
||||
return None
|
||||
|
||||
# Check for notification.html template in datastore directory
|
||||
notification_template_path = os.path.join(datastore.datastore_path, 'notification.html')
|
||||
notification_template = None
|
||||
if os.path.exists(notification_template_path):
|
||||
try:
|
||||
with open(notification_template_path, 'r', encoding='utf-8') as f:
|
||||
notification_template = f.read()
|
||||
logger.info(f"Using notification template from {notification_template_path}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to load notification template {notification_template_path}: {e}")
|
||||
|
||||
with apprise.LogCapture(level=apprise.logging.DEBUG) as logs:
|
||||
for url in n_object['notification_urls']:
|
||||
|
||||
# Get the notification body from datastore
|
||||
n_body = jinja_render(template_str=n_object.get('notification_body', ''), **notification_parameters)
|
||||
|
||||
# Apply notification template wrapper if it exists
|
||||
if notification_template:
|
||||
template_params = notification_parameters.copy()
|
||||
template_params['notification_body'] = n_body
|
||||
template_params['notification_url_current'] = url
|
||||
n_body = jinja_render(template_str=notification_template, **template_params)
|
||||
|
||||
if n_object.get('notification_format', '').startswith('HTML'):
|
||||
n_body = n_body.replace("\n", '<br>')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user