Tidyups for single watch feed

RSS-per-watch-tweaks
dgtlmoon 2025-11-13 19:59:54 +01:00
rodzic 629f939224
commit 9a6a131985
1 zmienionych plików z 48 dodań i 7 usunięć

Wyświetl plik

@ -2,6 +2,7 @@ from flask import make_response, request, url_for
from feedgen.feed import FeedGenerator
import datetime
import pytz
import locale
from ._util import generate_watch_guid, generate_watch_diff_content
@ -53,7 +54,16 @@ def construct_single_watch_routes(rss_blueprint, datastore):
# Create RSS feed
fg = FeedGenerator()
fg.title(f'changedetection.io - {watch.label}')
# Set title: use "label (url)" if label differs from url, otherwise just url
watch_url = watch.get('url', '')
watch_label = watch.label
if watch_label and watch_label != watch_url:
feed_title = f'changedetection.io - {watch_label} ({watch_url})'
else:
feed_title = f'changedetection.io - {watch_url}'
fg.title(feed_title)
fg.description('Changes')
fg.link(href='https://changedetection.io')
@ -70,15 +80,33 @@ def construct_single_watch_routes(rss_blueprint, datastore):
try:
# Generate the diff content for this pair of snapshots
timestamp_to = dates[date_index_to]
timestamp_from = dates[date_index_from]
content, watch_label = generate_watch_diff_content(
watch, dates, rss_content_format, datastore,
date_index_from=date_index_from,
date_index_to=date_index_to
)
# Generate edit watch link and add to content
edit_watch_url = url_for('ui.ui_edit.edit_page',
uuid=watch['uuid'],
_external=True)
# Add edit watch links at top and bottom of content
if 'html' in rss_content_format:
edit_link_html = f'<p><a href="{edit_watch_url}">[edit watch]</a></p>'
# Insert after <body> and before </body>
content = content.replace('<body>', f'<body>\n{edit_link_html}', 1)
content = content.replace('</body>', f'{edit_link_html}\n</body>', 1)
else:
# For plain text format, add plain text links in separate <pre> blocks
edit_link_top = f'<pre>[edit watch] {edit_watch_url}</pre>\n'
edit_link_bottom = f'\n<pre>[edit watch] {edit_watch_url}</pre>'
content = edit_link_top + content + edit_link_bottom
# Create a unique GUID for this specific diff
timestamp_to = dates[date_index_to]
timestamp_from = dates[date_index_from]
guid = f"{watch['uuid']}/{timestamp_to}"
fe = fg.add_entry()
@ -91,14 +119,27 @@ def construct_single_watch_routes(rss_blueprint, datastore):
_external=True)}
fe.link(link=diff_link)
# Add timestamp info to title to distinguish different diffs
fe.title(title=f"{watch_label} - Change {i+1}")
# Format the date using locale-aware formatting with timezone
dt = datetime.datetime.fromtimestamp(int(timestamp_to))
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()
# Use formatted date in title instead of "Change 1, 2, 3"
fe.title(title=f"{watch_label} - Change @ {formatted_date}")
fe.content(content=content, type='CDATA')
fe.guid(guid, permalink=False)
# Use the timestamp of the "to" snapshot for pubDate
dt = datetime.datetime.fromtimestamp(int(timestamp_to))
dt = dt.replace(tzinfo=pytz.UTC)
fe.pubDate(dt)
except (IndexError, FileNotFoundError) as e: