From 5ef110acc9672ecae5b89478ff58a25be6a12027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Thu, 22 Dec 2022 23:07:22 +0100 Subject: [PATCH] Split the words in blacklist and whitelist --- discord_rss_bot/blacklist.py | 19 +++++++++++++------ discord_rss_bot/templates/blacklist.html | 9 +++++---- discord_rss_bot/templates/whitelist.html | 8 ++++---- discord_rss_bot/whitelist.py | 19 +++++++++++++------ 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/discord_rss_bot/blacklist.py b/discord_rss_bot/blacklist.py index b48e09d..351bcbd 100644 --- a/discord_rss_bot/blacklist.py +++ b/discord_rss_bot/blacklist.py @@ -3,19 +3,26 @@ import re from reader import Entry, Feed, Reader, TagNotFoundError -def is_word_in_text(word: str, text: str) -> bool: +def is_word_in_text(words: str, text: str) -> bool: """ Args: - word: The word to search for. + words: The words to search for. text: The text to search in. Returns: bool: If the word is in the text. """ - pattern = rf"(^|[^\w]){word}([^\w]|$)" - pattern = re.compile(pattern, re.IGNORECASE) - matches = re.search(pattern, text) - return bool(matches) + # Split the word list into a list of words. + word_list = words.split(",") + + # Check if each word is in the text. + for word in word_list: + pattern = rf"(^|[^\w]){word}([^\w]|$)" + pattern = re.compile(pattern, re.IGNORECASE) + matches = re.search(pattern, text) + if matches: + return True + return False def has_black_tags(custom_reader: Reader, feed: Feed) -> bool: diff --git a/discord_rss_bot/templates/blacklist.html b/discord_rss_bot/templates/blacklist.html index 0db4b3d..7714de0 100644 --- a/discord_rss_bot/templates/blacklist.html +++ b/discord_rss_bot/templates/blacklist.html @@ -9,19 +9,20 @@
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. + blacklist. Leave empty to disable. Words are case-insensitive. No spaces should be used before + or after the comma.
+ id="blacklist_title" placeholder="primogem,events,gameplay preview,special program"> + id="blacklist_summary" placeholder="primogem,events,gameplay preview,special program"> + id="blacklist_content" placeholder="primogem,events,gameplay preview,special program">
diff --git a/discord_rss_bot/templates/whitelist.html b/discord_rss_bot/templates/whitelist.html index dd09309..3e91fc2 100644 --- a/discord_rss_bot/templates/whitelist.html +++ b/discord_rss_bot/templates/whitelist.html @@ -10,19 +10,19 @@
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. + Words are case-insensitive. No spaces should be used before or after the comma.
+ id="whitelist_title" placeholder="primogem,events,gameplay preview,special program"> + id="whitelist_summary" placeholder="primogem,events,gameplay preview,special program"> + id="whitelist_content" placeholder="primogem,events,gameplay preview,special program"> diff --git a/discord_rss_bot/whitelist.py b/discord_rss_bot/whitelist.py index 0b314cf..57f3ac8 100644 --- a/discord_rss_bot/whitelist.py +++ b/discord_rss_bot/whitelist.py @@ -3,19 +3,26 @@ import re from reader import Entry, Feed, Reader, TagNotFoundError -def is_word_in_text(word: str, text: str) -> bool: +def is_word_in_text(words: str, text: str) -> bool: """ Args: - word: The word to search for. + words: The words to search for. text: The text to search in. Returns: bool: If the word is in the text. """ - pattern = rf"(^|[^\w]){word}([^\w]|$)" - pattern = re.compile(pattern, re.IGNORECASE) - matches = re.search(pattern, text) - return bool(matches) + # Split the word list into a list of words. + word_list = words.split(",") + + # Check if each word is in the text. + for word in word_list: + pattern = rf"(^|[^\w]){word}([^\w]|$)" + pattern = re.compile(pattern, re.IGNORECASE) + matches = re.search(pattern, text) + if matches: + return True + return False def has_white_tags(custom_reader: Reader, feed: Feed) -> bool: