Move blacklist and whitelist to own directory

This commit is contained in:
2023-01-11 00:49:15 +01:00
parent 6ba70a133d
commit 6c4719cd99
5 changed files with 46 additions and 55 deletions

View File

@ -5,9 +5,9 @@ from reader import Entry, Feed, Reader
from requests import Response from requests import Response
from discord_rss_bot import settings from discord_rss_bot import settings
from discord_rss_bot.blacklist import should_be_skipped from discord_rss_bot.filter.blacklist import should_be_skipped
from discord_rss_bot.settings import get_reader from discord_rss_bot.settings import get_reader
from discord_rss_bot.whitelist import has_white_tags, should_be_sent from discord_rss_bot.filter.whitelist import has_white_tags, should_be_sent
def send_to_discord(custom_reader: Reader | None = None, feed: Feed | None = None, do_once: bool = False) -> None: def send_to_discord(custom_reader: Reader | None = None, feed: Feed | None = None, do_once: bool = False) -> None:

View File

@ -1,27 +1,6 @@
import re
from reader import Entry, Feed, Reader, TagNotFoundError from reader import Entry, Feed, Reader, TagNotFoundError
from discord_rss_bot.filter.utils import is_word_in_text
def is_word_in_text(words: str, text: str) -> bool:
"""
Args:
words: The words to search for.
text: The text to search in.
Returns:
bool: If the word is in the text.
"""
# Split the word list into a list of words.
word_list: list[str] = words.split(",")
# Check if each word is in the text.
for word in word_list:
look_for: str = rf"(^|[^\w]){word}([^\w]|$)"
pattern: re.Pattern[str] = re.compile(look_for, re.IGNORECASE)
if re.search(pattern, text):
return True
return False
def has_black_tags(custom_reader: Reader, feed: Feed) -> bool: def has_black_tags(custom_reader: Reader, feed: Feed) -> bool:

View File

@ -0,0 +1,22 @@
import re
def is_word_in_text(words: str, text: str) -> bool:
"""
Args:
words: The words to search for.
text: The text to search in.
Returns:
bool: If the word is in the text.
"""
# Split the word list into a list of words.
word_list: list[str] = words.split(",")
# Check if each word is in the text.
for word in word_list:
look_for: str = rf"(^|[^\w]){word}([^\w]|$)"
pattern: re.Pattern[str] = re.compile(look_for, re.IGNORECASE)
if re.search(pattern, text):
return True
return False

View File

@ -1,27 +1,6 @@
import re
from reader import Entry, Feed, Reader, TagNotFoundError from reader import Entry, Feed, Reader, TagNotFoundError
from discord_rss_bot.filter.utils import is_word_in_text
def is_word_in_text(words: str, text: str) -> bool:
"""
Args:
words: The words to search for.
text: The text to search in.
Returns:
bool: If the word is in the text.
"""
# Split the word list into a list of words.
word_list: list[str] = words.split(",")
# Check if each word is in the text.
for word in word_list:
look_for: str = rf"(^|[^\w]){word}([^\w]|$)"
pattern: re.Pattern[str] = re.compile(look_for, re.IGNORECASE)
if re.search(pattern, text):
return True
return False
def has_white_tags(custom_reader: Reader, feed: Feed) -> bool: def has_white_tags(custom_reader: Reader, feed: Feed) -> bool:

View File

@ -11,12 +11,23 @@ from fastapi.templating import Jinja2Templates
from reader import Entry, EntryCounts, EntrySearchCounts, EntrySearchResult, Feed, FeedCounts, Reader, TagNotFoundError from reader import Entry, EntryCounts, EntrySearchCounts, EntrySearchResult, Feed, FeedCounts, Reader, TagNotFoundError
from starlette.responses import RedirectResponse from starlette.responses import RedirectResponse
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.feeds import send_to_discord
from discord_rss_bot.filter.blacklist import (
get_blacklist_content,
get_blacklist_summary,
get_blacklist_title,
has_black_tags,
should_be_skipped,
)
from discord_rss_bot.filter.whitelist import (
get_whitelist_content,
get_whitelist_summary,
get_whitelist_title,
has_white_tags,
should_be_sent,
)
from discord_rss_bot.search import create_html_for_search_results from discord_rss_bot.search import create_html_for_search_results
from discord_rss_bot.settings import get_reader, list_webhooks from discord_rss_bot.settings import get_reader, list_webhooks
from discord_rss_bot.whitelist import has_white_tags, should_be_sent
app: FastAPI = FastAPI() app: FastAPI = FastAPI()
app.mount("/static", StaticFiles(directory="discord_rss_bot/static"), name="static") app.mount("/static", StaticFiles(directory="discord_rss_bot/static"), name="static")
@ -278,9 +289,9 @@ async def get_whitelist(feed_url: str, request: Request):
feed: Feed = reader.get_feed(url) feed: Feed = reader.get_feed(url)
# Get previous data, this is used when creating the form. # Get previous data, this is used when creating the form.
whitelist_title: str = whitelist.get_whitelist_title(reader, feed) whitelist_title: str = get_whitelist_title(reader, feed)
whitelist_summary: str = whitelist.get_whitelist_summary(reader, feed) whitelist_summary: str = get_whitelist_summary(reader, feed)
whitelist_content: str = whitelist.get_whitelist_content(reader, feed) whitelist_content: str = get_whitelist_content(reader, feed)
context = { context = {
"request": request, "request": request,
@ -334,9 +345,9 @@ async def get_blacklist(feed_url: str, request: Request):
feed: Feed = reader.get_feed(url) feed: Feed = reader.get_feed(url)
# Get previous data, this is used when creating the form. # Get previous data, this is used when creating the form.
blacklist_title: str = blacklist.get_blacklist_title(reader, feed) blacklist_title: str = get_blacklist_title(reader, feed)
blacklist_summary: str = blacklist.get_blacklist_summary(reader, feed) blacklist_summary: str = get_blacklist_summary(reader, feed)
blacklist_content: str = blacklist.get_blacklist_content(reader, feed) blacklist_content: str = get_blacklist_content(reader, feed)
context = { context = {
"request": request, "request": request,