diff --git a/.env.example b/.env.example
index 90e4cce..2a098da 100644
--- a/.env.example
+++ b/.env.example
@@ -1,4 +1,4 @@
-# You can optionally store backups of your bot's configuration in a git repository.
+# You can optionally store backups of your bot's configuration in a git repository.
# This allows you to track changes by subscribing to the repository or using a RSS feed.
# Local path for the backup git repository (e.g., /data/backup or /home/user/backups/discord-rss-bot)
# When set, the bot will initialize a git repo here and commit state.json after every configuration change
diff --git a/discord_rss_bot/filter/blacklist.py b/discord_rss_bot/filter/blacklist.py
index 87b4913..95c0716 100644
--- a/discord_rss_bot/filter/blacklist.py
+++ b/discord_rss_bot/filter/blacklist.py
@@ -2,10 +2,13 @@ from __future__ import annotations
from typing import TYPE_CHECKING
-from discord_rss_bot.filter.utils import is_regex_match, is_word_in_text
+from discord_rss_bot.filter.utils import is_regex_match
+from discord_rss_bot.filter.utils import is_word_in_text
if TYPE_CHECKING:
- from reader import Entry, Feed, Reader
+ from reader import Entry
+ from reader import Feed
+ from reader import Reader
def feed_has_blacklist_tags(custom_reader: Reader, feed: Feed) -> bool:
diff --git a/discord_rss_bot/filter/whitelist.py b/discord_rss_bot/filter/whitelist.py
index b4b5c23..9c198c4 100644
--- a/discord_rss_bot/filter/whitelist.py
+++ b/discord_rss_bot/filter/whitelist.py
@@ -2,10 +2,13 @@ from __future__ import annotations
from typing import TYPE_CHECKING
-from discord_rss_bot.filter.utils import is_regex_match, is_word_in_text
+from discord_rss_bot.filter.utils import is_regex_match
+from discord_rss_bot.filter.utils import is_word_in_text
if TYPE_CHECKING:
- from reader import Entry, Feed, Reader
+ from reader import Entry
+ from reader import Feed
+ from reader import Reader
def has_white_tags(custom_reader: Reader, feed: Feed) -> bool:
diff --git a/discord_rss_bot/git_backup.py b/discord_rss_bot/git_backup.py
index 4106d21..cac3b88 100644
--- a/discord_rss_bot/git_backup.py
+++ b/discord_rss_bot/git_backup.py
@@ -179,7 +179,7 @@ def export_state(reader: Reader, backup_path: Path) -> None:
try:
webhooks: list[str | int | float | bool | dict[str, Any] | list[Any] | None] = list(
- reader.get_tag((), "webhooks", [])
+ reader.get_tag((), "webhooks", []),
)
except TagNotFoundError:
webhooks = []
diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py
index 2e7af0f..e4e8975 100644
--- a/discord_rss_bot/main.py
+++ b/discord_rss_bot/main.py
@@ -31,8 +31,10 @@ from markdownify import markdownify
from reader import Entry
from reader import EntryNotFoundError
from reader import Feed
+from reader import FeedExistsError
from reader import FeedNotFoundError
from reader import Reader
+from reader import ReaderError
from reader import TagNotFoundError
from starlette.responses import RedirectResponse
@@ -697,6 +699,45 @@ async def post_set_update_interval(
return RedirectResponse(url=f"/feed?feed_url={urllib.parse.quote(clean_feed_url)}", status_code=303)
+@app.post("/change_feed_url")
+async def post_change_feed_url(
+ old_feed_url: Annotated[str, Form()],
+ new_feed_url: Annotated[str, Form()],
+) -> RedirectResponse:
+ """Change the URL for an existing feed.
+
+ Args:
+ old_feed_url: Current feed URL.
+ new_feed_url: New feed URL to change to.
+
+ Returns:
+ RedirectResponse: Redirect to the feed page for the resulting URL.
+
+ Raises:
+ HTTPException: If the old feed is not found, the new URL already exists, or change fails.
+ """
+ clean_old_feed_url: str = old_feed_url.strip()
+ clean_new_feed_url: str = new_feed_url.strip()
+
+ if not clean_old_feed_url or not clean_new_feed_url:
+ raise HTTPException(status_code=400, detail="Feed URLs cannot be empty")
+
+ if clean_old_feed_url == clean_new_feed_url:
+ return RedirectResponse(url=f"/feed?feed_url={urllib.parse.quote(clean_old_feed_url)}", status_code=303)
+
+ try:
+ reader.change_feed_url(clean_old_feed_url, clean_new_feed_url)
+ except FeedNotFoundError as e:
+ raise HTTPException(status_code=404, detail=f"Feed not found: {clean_old_feed_url}") from e
+ except FeedExistsError as e:
+ raise HTTPException(status_code=409, detail=f"Feed already exists: {clean_new_feed_url}") from e
+ except ReaderError as e:
+ raise HTTPException(status_code=400, detail=f"Failed to change feed URL: {e}") from e
+
+ commit_state_change(reader, f"Change feed URL from {clean_old_feed_url} to {clean_new_feed_url}")
+ return RedirectResponse(url=f"/feed?feed_url={urllib.parse.quote(clean_new_feed_url)}", status_code=303)
+
+
@app.post("/reset_update_interval")
async def post_reset_update_interval(
feed_url: Annotated[str, Form()],
@@ -804,7 +845,7 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
except EntryNotFoundError as e:
current_entries = list(reader.get_entries(feed=clean_feed_url))
msg: str = f"{e}\n\n{[entry.id for entry in current_entries]}"
- html: str = create_html_for_feed(current_entries)
+ html: str = create_html_for_feed(current_entries, clean_feed_url)
# Get feed and global intervals for error case too
feed_interval: int | None = None
@@ -860,7 +901,7 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
last_entry = entries[-1]
# Create the html for the entries.
- html: str = create_html_for_feed(entries)
+ html: str = create_html_for_feed(entries, clean_feed_url)
try:
should_send_embed: bool = bool(reader.get_tag(feed, "should_send_embed"))
@@ -907,11 +948,12 @@ async def get_feed(feed_url: str, request: Request, starting_after: str = ""):
return templates.TemplateResponse(request=request, name="feed.html", context=context)
-def create_html_for_feed(entries: Iterable[Entry]) -> str:
+def create_html_for_feed(entries: Iterable[Entry], current_feed_url: str = "") -> str: # noqa: PLR0914
"""Create HTML for the search results.
Args:
entries: The entries to create HTML for.
+ current_feed_url: The feed URL currently being viewed in /feed.
Returns:
str: The HTML for the search results.
@@ -940,6 +982,12 @@ def create_html_for_feed(entries: Iterable[Entry]) -> str:
if entry_is_whitelisted(entry):
whitelisted = "Whitelisted"
+ source_feed_url: str = getattr(entry, "original_feed_url", None) or entry.feed.url
+
+ from_another_feed: str = ""
+ if current_feed_url and source_feed_url != current_feed_url:
+ from_another_feed = f"From another feed: {source_feed_url}"
+
entry_id: str = urllib.parse.quote(entry.id)
to_discord_html: str = f"Send to Discord"
@@ -966,14 +1014,14 @@ def create_html_for_feed(entries: Iterable[Entry]) -> str:
image_html: str = f"" if first_image else ""
html += f"""
Change the URL for this feed. This can be useful if a feed has moved.
+ +