Split the words in blacklist and whitelist

This commit is contained in:
2022-12-22 23:07:22 +01:00
parent f4f9bc1058
commit 5ef110acc9
4 changed files with 35 additions and 20 deletions

View File

@ -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:

View File

@ -9,19 +9,20 @@
<div class="col-sm-12">
<div class="form-text">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.
</div>
<label for="blacklist_title" class="col-sm-6 col-form-label">Blacklist - Title</label>
<input name="blacklist_title" type="text" class="form-control bg-dark border-dark text-muted"
id="blacklist_title" placeholder="primogem, events, gameplay preview, special program">
id="blacklist_title" placeholder="primogem,events,gameplay preview,special program">
<label for="blacklist_summary" class="col-sm-6 col-form-label">Blacklist - Summary</label>
<input name="blacklist_summary" type="text" class="form-control bg-dark border-dark text-muted"
id="blacklist_summary" placeholder="primogem, events, gameplay preview, special program">
id="blacklist_summary" placeholder="primogem,events,gameplay preview,special program">
<label for="blacklist_content" class="col-sm-6 col-form-label">Blacklist - Content</label>
<input name="blacklist_content" type="text" class="form-control bg-dark border-dark text-muted"
id="blacklist_content" placeholder="primogem, events, gameplay preview, special program">
id="blacklist_content" placeholder="primogem,events,gameplay preview,special program">
</div>
</div>

View File

@ -10,19 +10,19 @@
<div class="form-text">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.
</div>
<label for="whitelist_title" class="col-sm-6 col-form-label">Whitelist - Title</label>
<input name="whitelist_title" type="text" class="form-control bg-dark border-dark text-muted"
id="whitelist_title" placeholder="primogem, events, gameplay preview, special program">
id="whitelist_title" placeholder="primogem,events,gameplay preview,special program">
<label for="whitelist_summary" class="col-sm-6 col-form-label">Whitelist - Summary</label>
<input name="whitelist_summary" type="text" class="form-control bg-dark border-dark text-muted"
id="whitelist_summary" placeholder="primogem, events, gameplay preview, special program">
id="whitelist_summary" placeholder="primogem,events,gameplay preview,special program">
<label for="whitelist_content" class="col-sm-6 col-form-label">Whitelist - Content</label>
<input name="whitelist_content" type="text" class="form-control bg-dark border-dark text-muted"
id="whitelist_content" placeholder="primogem, events, gameplay preview, special program">
id="whitelist_content" placeholder="primogem,events,gameplay preview,special program">
</div>
</div>

View File

@ -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: