diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py index c0d1bc1..e37d4c6 100644 --- a/discord_rss_bot/main.py +++ b/discord_rss_bot/main.py @@ -49,6 +49,7 @@ from reader import ( from starlette.responses import RedirectResponse from starlette.templating import _TemplateResponse # noqa +from discord_rss_bot import blacklist, whitelist from discord_rss_bot.blacklist import has_black_tags, should_be_skipped from discord_rss_bot.feeds import send_to_discord from discord_rss_bot.search import create_html_for_search_results @@ -284,8 +285,6 @@ async def set_whitelist( Returns: Redirect back to the feed page. """ - # Add the whitelist to the feed. - if whitelist_title: reader.set_tag(feed_url, "whitelist_title", whitelist_title) # type: ignore if whitelist_summary: @@ -314,12 +313,19 @@ async def get_whitelist(feed_url: str, request: Request) -> _TemplateResponse: url: str = urllib.parse.unquote(feed_url) feed: Feed = reader.get_feed(url) - try: - whitelist: str = reader.get_tag(url, "whitelist") # type: ignore - except TagNotFoundError: - whitelist: str = "" - context = {"request": request, "feed": feed, "whitelist": whitelist} + # Get previous data, this is used when creating the form. + whitelist_title = whitelist.get_whitelist_title(reader, feed) + whitelist_summary = whitelist.get_whitelist_summary(reader, feed) + whitelist_content = whitelist.get_whitelist_content(reader, feed) + + context = { + "request": request, + "feed": feed, + "whitelist_title": whitelist_title, + "whitelist_summary": whitelist_summary, + "whitelist_content": whitelist_content, + } return templates.TemplateResponse("whitelist.html", context) @@ -362,12 +368,19 @@ async def get_blacklist(feed_url: str, request: Request) -> _TemplateResponse: url: str = urllib.parse.unquote(feed_url) feed: Feed = reader.get_feed(url) - try: - blacklist: str = reader.get_tag(url, "blacklist") # type: ignore - except TagNotFoundError: - blacklist: str = "" - context = {"request": request, "feed": feed, "blacklist": blacklist} + # Get previous data, this is used when creating the form. + blacklist_title = blacklist.get_blacklist_title(reader, feed) + blacklist_summary = blacklist.get_blacklist_summary(reader, feed) + blacklist_content = blacklist.get_blacklist_content(reader, feed) + + context = { + "request": request, + "feed": feed, + "blacklist_title": blacklist_title, + "blacklist_summary": blacklist_summary, + "blacklist_content": blacklist_content, + } return templates.TemplateResponse("blacklist.html", context) diff --git a/discord_rss_bot/templates/blacklist.html b/discord_rss_bot/templates/blacklist.html index a5094c8..97f7b47 100644 --- a/discord_rss_bot/templates/blacklist.html +++ b/discord_rss_bot/templates/blacklist.html @@ -7,22 +7,40 @@
-
Comma separated list of words to blacklist. If a word is found in the - corresponding blacklists, the feed will not be sent. Whitelist always takes precedence over - blacklist. Leave empty to disable. Words are case-insensitive. No spaces should be used before - or after the comma. +
+
    +
  • Comma separated list of words to blacklist. If a word is found in the + corresponding blacklists, the feed will not be sent. +
  • +
  • Whitelist always takes precedence over blacklist. Leave empty to disable.
  • +
  • Words are case-insensitive. No spaces should be used before or after the comma.
  • + +
  • + Correct: + + primogem,events,gameplay preview,special program + +
  • +
  • + Wrong: + + primogem, events, gameplay preview, special program + +
  • +
+
+ id="blacklist_title" value="{% if whitelist_title %}{{ whitelist_title }}{% endif %}"> + id="blacklist_summary" value="{% if blacklist_summary %}{{ blacklist_summary }}{% endif %}"> + id="blacklist_content" value="{% if blacklist_content %}{{ blacklist_content }}{% endif %}">
diff --git a/discord_rss_bot/templates/whitelist.html b/discord_rss_bot/templates/whitelist.html index 58b5b83..d5c8b84 100644 --- a/discord_rss_bot/templates/whitelist.html +++ b/discord_rss_bot/templates/whitelist.html @@ -7,22 +7,40 @@
-
Comma separated list of words to whitelist. Only send message to - Discord if one of these words are present in the corresponding fields. - Whitelist always takes precedence over blacklist. Leave empty to disable. - Words are case-insensitive. No spaces should be used before or after the comma. +
+
    +
  • Comma separated list of words to whitelist. Only send message to + Discord if one of these words are present in the corresponding fields. +
  • +
  • Whitelist always takes precedence over blacklist. Leave empty to disable.
  • +
  • Words are case-insensitive. No spaces should be used before or after the comma.
  • + +
  • + Correct: + + primogem,events,gameplay preview,special program + +
  • +
  • + Wrong: + + primogem, events, gameplay preview, special program + +
  • +
+ + id="whitelist_title" value="{% if whitelist_title %}{{ whitelist_title }}{% endif %}"> + id="whitelist_summary" value="{% if whitelist_summary %}{{ whitelist_summary }}{% endif %}"> + id="whitelist_content" value="{% if whitelist_content %}{{ whitelist_content }}{% endif %}">