Add docstrings
This commit is contained in:
@ -63,8 +63,9 @@ reader: Reader = get_reader()
|
|||||||
|
|
||||||
|
|
||||||
def encode_url(url_to_quote: str) -> str:
|
def encode_url(url_to_quote: str) -> str:
|
||||||
"""%-escape the URL so it can be used in a URL. If we didn't do this, we couldn't go to feeds with a ? in the URL.
|
"""%-escape the URL so it can be used in a URL.
|
||||||
|
|
||||||
|
If we didn't do this, we couldn't go to feeds with a ? in the URL.
|
||||||
You can use this in templates with {{ url | encode_url }}.
|
You can use this in templates with {{ url | encode_url }}.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -73,10 +74,8 @@ def encode_url(url_to_quote: str) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
The encoded url.
|
The encoded url.
|
||||||
"""
|
"""
|
||||||
if url_to_quote:
|
|
||||||
return urllib.parse.quote(url_to_quote)
|
|
||||||
return "None"
|
|
||||||
# TODO: Send error to Discord.
|
# TODO: Send error to Discord.
|
||||||
|
return urllib.parse.quote(url_to_quote) if url_to_quote else "None"
|
||||||
|
|
||||||
|
|
||||||
def entry_is_whitelisted(entry_to_check: Entry) -> bool:
|
def entry_is_whitelisted(entry_to_check: Entry) -> bool:
|
||||||
@ -90,10 +89,7 @@ def entry_is_whitelisted(entry_to_check: Entry) -> bool:
|
|||||||
bool: True if the feed is whitelisted, False otherwise.
|
bool: True if the feed is whitelisted, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if has_white_tags(reader, entry_to_check.feed):
|
return bool(has_white_tags(reader, entry_to_check.feed) and should_be_sent(reader, entry_to_check))
|
||||||
if should_be_sent(reader, entry_to_check):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def entry_is_blacklisted(entry_to_check: Entry) -> bool:
|
def entry_is_blacklisted(entry_to_check: Entry) -> bool:
|
||||||
@ -107,10 +103,7 @@ def entry_is_blacklisted(entry_to_check: Entry) -> bool:
|
|||||||
bool: True if the feed is blacklisted, False otherwise.
|
bool: True if the feed is blacklisted, False otherwise.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if has_black_tags(reader, entry_to_check.feed):
|
return bool(has_black_tags(reader, entry_to_check.feed) and should_be_skipped(reader, entry_to_check))
|
||||||
if should_be_skipped(reader, entry_to_check):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
templates.env.filters["encode_url"] = encode_url
|
templates.env.filters["encode_url"] = encode_url
|
||||||
@ -135,10 +128,10 @@ async def add_webhook(webhook_name: str = Form(), webhook_url: str = Form()) ->
|
|||||||
clean_webhook_url: str = webhook_url.strip()
|
clean_webhook_url: str = webhook_url.strip()
|
||||||
|
|
||||||
# Get current webhooks from the database if they exist otherwise use an empty list.
|
# Get current webhooks from the database if they exist otherwise use an empty list.
|
||||||
webhooks = list_webhooks(reader)
|
webhooks: list[dict[str, str]] = list_webhooks(reader)
|
||||||
|
|
||||||
# Only add the webhook if it doesn't already exist.
|
# Only add the webhook if it doesn't already exist.
|
||||||
if not any(webhook["name"] == clean_webhook_name for webhook in webhooks):
|
if all(webhook["name"] != clean_webhook_name for webhook in webhooks):
|
||||||
# Create a dict with webhook name and URL.
|
# Create a dict with webhook name and URL.
|
||||||
new_webhook: dict[str, str] = {"name": clean_webhook_name, "url": clean_webhook_url}
|
new_webhook: dict[str, str] = {"name": clean_webhook_name, "url": clean_webhook_url}
|
||||||
|
|
||||||
@ -216,7 +209,7 @@ async def create_feed(feed_url: str = Form(), webhook_dropdown: str = Form()) ->
|
|||||||
hooks = []
|
hooks = []
|
||||||
|
|
||||||
webhook_url = ""
|
webhook_url = ""
|
||||||
if len(hooks) > 0:
|
if hooks:
|
||||||
# Get the webhook URL from the dropdown.
|
# Get the webhook URL from the dropdown.
|
||||||
for hook in hooks:
|
for hook in hooks:
|
||||||
if hook["name"] == webhook_dropdown:
|
if hook["name"] == webhook_dropdown:
|
||||||
@ -237,6 +230,14 @@ async def create_feed(feed_url: str = Form(), webhook_dropdown: str = Form()) ->
|
|||||||
|
|
||||||
@app.post("/pause")
|
@app.post("/pause")
|
||||||
async def pause_feed(feed_url: str = Form()) -> dict[str, str] | RedirectResponse:
|
async def pause_feed(feed_url: str = Form()) -> dict[str, str] | RedirectResponse:
|
||||||
|
"""Pause a feed.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
feed_url: The feed to pause. Defaults to Form().
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Redirect the URL to the feed we paused.
|
||||||
|
"""
|
||||||
# Disable/pause the feed.
|
# Disable/pause the feed.
|
||||||
reader.disable_feed_updates(feed_url)
|
reader.disable_feed_updates(feed_url)
|
||||||
|
|
||||||
@ -248,6 +249,14 @@ async def pause_feed(feed_url: str = Form()) -> dict[str, str] | RedirectRespons
|
|||||||
|
|
||||||
@app.post("/unpause")
|
@app.post("/unpause")
|
||||||
async def unpause_feed(feed_url: str = Form()) -> dict[str, str] | RedirectResponse:
|
async def unpause_feed(feed_url: str = Form()) -> dict[str, str] | RedirectResponse:
|
||||||
|
"""Unpause a feed.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
feed_url: The feed to unpause. Defaults to Form().
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Redirect to the feed we unpaused.
|
||||||
|
"""
|
||||||
# Enable/unpause the feed.
|
# Enable/unpause the feed.
|
||||||
reader.enable_feed_updates(feed_url)
|
reader.enable_feed_updates(feed_url)
|
||||||
|
|
||||||
@ -264,6 +273,17 @@ async def set_whitelist(
|
|||||||
whitelist_content: str = Form(None),
|
whitelist_content: str = Form(None),
|
||||||
feed_url: str = Form(),
|
feed_url: str = Form(),
|
||||||
) -> RedirectResponse:
|
) -> RedirectResponse:
|
||||||
|
"""Set what the whitelist should be sent, if you have this set only words in the whitelist will be sent.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
whitelist_title: Whitelisted words for when checking the title.
|
||||||
|
whitelist_summary: Whitelisted words for when checking the title.
|
||||||
|
whitelist_content: Whitelisted words for when checking the title.
|
||||||
|
feed_url: The feed we should set the whitelist for.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Redirect back to the feed page.
|
||||||
|
"""
|
||||||
# Add the whitelist to the feed.
|
# Add the whitelist to the feed.
|
||||||
|
|
||||||
if whitelist_title:
|
if whitelist_title:
|
||||||
@ -281,12 +301,21 @@ async def set_whitelist(
|
|||||||
|
|
||||||
@app.get("/whitelist", response_class=HTMLResponse)
|
@app.get("/whitelist", response_class=HTMLResponse)
|
||||||
async def get_whitelist(feed_url: str, request: Request) -> _TemplateResponse:
|
async def get_whitelist(feed_url: str, request: Request) -> _TemplateResponse:
|
||||||
|
"""Get the whitelist.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
feed_url: What feed we should get the whitelist for.
|
||||||
|
request: The HTTP request.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
_description_
|
||||||
|
"""
|
||||||
# Make feed_url a valid URL.
|
# Make feed_url a valid URL.
|
||||||
url: str = urllib.parse.unquote(feed_url)
|
url: str = urllib.parse.unquote(feed_url)
|
||||||
|
|
||||||
feed: Feed = reader.get_feed(url)
|
feed: Feed = reader.get_feed(url)
|
||||||
try:
|
try:
|
||||||
whitelist: str = reader.get_tag(url, "whitelist")
|
whitelist: str = reader.get_tag(url, "whitelist") # type: ignore
|
||||||
except TagNotFoundError:
|
except TagNotFoundError:
|
||||||
whitelist: str = ""
|
whitelist: str = ""
|
||||||
|
|
||||||
@ -301,6 +330,17 @@ async def set_blacklist(
|
|||||||
blacklist_content: str = Form(None),
|
blacklist_content: str = Form(None),
|
||||||
feed_url: str = Form(),
|
feed_url: str = Form(),
|
||||||
) -> RedirectResponse:
|
) -> RedirectResponse:
|
||||||
|
"""Set the blacklist, if this is set we will check if words are in the title, summary or content and then don't send that entry.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
blacklist_title: Blacklisted words for when checking the title.
|
||||||
|
blacklist_summary: Blacklisted words for when checking the summary.
|
||||||
|
blacklist_content: Blacklisted words for when checking the content.
|
||||||
|
feed_url: What feed we should set the blacklist for.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Redirect to the feed.
|
||||||
|
"""
|
||||||
# Add the blacklist to the feed.
|
# Add the blacklist to the feed.
|
||||||
|
|
||||||
if blacklist_title:
|
if blacklist_title:
|
||||||
@ -323,7 +363,7 @@ async def get_blacklist(feed_url: str, request: Request) -> _TemplateResponse:
|
|||||||
|
|
||||||
feed: Feed = reader.get_feed(url)
|
feed: Feed = reader.get_feed(url)
|
||||||
try:
|
try:
|
||||||
blacklist: str = reader.get_tag(url, "blacklist")
|
blacklist: str = reader.get_tag(url, "blacklist") # type: ignore
|
||||||
except TagNotFoundError:
|
except TagNotFoundError:
|
||||||
blacklist: str = ""
|
blacklist: str = ""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user