Add a function for get_webhooks()

This commit is contained in:
2022-12-19 17:23:55 +01:00
parent ddb8dea7a1
commit 372c5bb3e7
2 changed files with 22 additions and 13 deletions

View File

@ -51,7 +51,7 @@ from starlette.templating import _TemplateResponse
from discord_rss_bot.feeds import send_to_discord
from discord_rss_bot.search import create_html_for_search_results
from discord_rss_bot.settings import get_reader
from discord_rss_bot.settings import get_reader, get_webhooks
app: FastAPI = FastAPI()
app.mount("/static", StaticFiles(directory="discord_rss_bot/static"), name="static")
@ -94,12 +94,7 @@ async def add_webhook(webhook_name: str = Form(), webhook_url: str = Form()) ->
clean_webhook_url: str = webhook_url.strip()
# Get current webhooks from the database if they exist otherwise use an empty list.
webhooks: list[dict[str, str]] = []
if reader.get_tags(()) is not None:
for tag in reader.get_tag_keys(()):
if tag == "webhooks":
webhooks = reader.get_tag((), "webhooks")
break
webhooks = get_webhooks(reader)
# Only add the webhook if it doesn't already exist.
if not any(webhook["name"] == clean_webhook_name for webhook in webhooks):
@ -134,12 +129,7 @@ async def delete_webhook(webhook_url: str = Form()) -> RedirectResponse | dict[s
clean_webhook_url: str = webhook_url.strip()
# Get current webhooks from the database if they exist otherwise use an empty list.
webhooks: list[dict[str, str]] = []
if reader.get_tags(()) is not None:
for tag in reader.get_tag_keys(()):
if tag == "webhooks":
webhooks = reader.get_tag((), "webhooks")
break
webhooks = get_webhooks(reader)
# Only add the webhook if it doesn't already exist.
for webhook in webhooks: