diff --git a/changedetectionio/notification_service.py b/changedetectionio/notification_service.py index 7046e652a..3290ff7b5 100644 --- a/changedetectionio/notification_service.py +++ b/changedetectionio/notification_service.py @@ -63,6 +63,7 @@ class FormattableTimestamp(str): {{ change_datetime }} → '2024-01-15 10:30:00 UTC' {{ change_datetime(format='%Y') }} → '2024' {{ change_datetime(format='%A') }} → 'Monday' + {{ change_datetime(format='%Y-%m-%d') }} → '2024-01-15' Being a str subclass means it is natively JSON serializable. """ @@ -142,9 +143,11 @@ class FormattableDiff(str): return result + # What is passed around as notification context, also used as the complete list of valid {{ tokens }} class NotificationContextData(dict): def __init__(self, initial_data=None, **kwargs): + # ValidateJinja2Template() validates against the keynames of this dict to check for valid tokens in the body (user submission) super().__init__({ 'base_url': None, 'change_datetime': FormattableTimestamp(time.time()), @@ -161,16 +164,18 @@ class NotificationContextData(dict): 'diff_url': None, 'markup_text_links_to_html_links': False, # If automatic conversion of plaintext to HTML should happen 'notification_timestamp': time.time(), + 'prev_snapshot': None, 'preview_url': None, 'screenshot': None, - 'triggered_text': None, 'timestamp_from': None, 'timestamp_to': None, + 'triggered_text': None, 'uuid': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', # Converted to 'watch_uuid' in create_notification_parameters 'watch_mime_type': None, 'watch_tag': None, 'watch_title': None, 'watch_url': 'https://WATCH-PLACE-HOLDER/', + 'watch_uuid': 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX', # Converted to 'watch_uuid' in create_notification_parameters }) # Apply any initial data passed in @@ -204,24 +209,6 @@ class NotificationContextData(dict): super().__setitem__(key, value) -def timestamp_to_localtime(timestamp): - # Format the date using locale-aware formatting with timezone - dt = datetime.datetime.fromtimestamp(int(timestamp)) - dt = dt.replace(tzinfo=pytz.UTC) - - # Get local timezone-aware datetime - local_tz = datetime.datetime.now().astimezone().tzinfo - local_dt = dt.astimezone(local_tz) - - # Format date with timezone - using strftime for locale awareness - try: - formatted_date = local_dt.strftime('%Y-%m-%d %H:%M:%S %Z') - except: - # Fallback if locale issues - formatted_date = local_dt.isoformat() - - return formatted_date - def add_rendered_diff_to_notification_vars(notification_scan_text:str, prev_snapshot:str, current_snapshot:str, word_diff:bool): """ Efficiently renders only the diff placeholders that are actually used in the notification text. diff --git a/changedetectionio/templates/_common_fields.html b/changedetectionio/templates/_common_fields.html index 43a551b3d..d99e949e5 100644 --- a/changedetectionio/templates/_common_fields.html +++ b/changedetectionio/templates/_common_fields.html @@ -44,6 +44,14 @@
{{ '{{preview_url}}' }}{{ '{{change_datetime}}' }}{{ '{{diff_url}}' }}{{ '{{diff_url}}' }}