From e045f072821fb1fd58cb0ff27b8a0ae2792b5a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Mon, 5 Dec 2022 11:41:05 +0100 Subject: [PATCH] Add docstrings to files --- discord_rss_bot/feeds.py | 23 +++++++++++++++++++++++ discord_rss_bot/main.py | 34 +++++++++++++++++++++++++++++++--- discord_rss_bot/settings.py | 22 ++++++++++++++++++++-- 3 files changed, 74 insertions(+), 5 deletions(-) diff --git a/discord_rss_bot/feeds.py b/discord_rss_bot/feeds.py index d91557a..e9c1265 100644 --- a/discord_rss_bot/feeds.py +++ b/discord_rss_bot/feeds.py @@ -1,3 +1,26 @@ +""" +Functions: + add_feed() + Add a feed to the reader. This also updates the feed. + check_feed() + Check a single feed. + check_feeds() + Check all feeds. + send_to_discord() + Send entries to Discord. + update_feed() + Update a feed. + +Classes: + IfFeedError + Used in add_feed() and update_feed(). If an error, it will return IfFeedError with error=True. + If no error, it will return IfFeedError with error=False. + +Exceptions: + NoWebhookFoundError + Used in send_to_discord(). If no webhook found, it will raise NoWebhookFoundError. +""" + from discord_webhook import DiscordWebhook from pydantic import BaseModel from reader import FeedExistsError, FeedNotFoundError, InvalidFeedURLError, ParseError, StorageError diff --git a/discord_rss_bot/main.py b/discord_rss_bot/main.py index 71b750d..52266c7 100644 --- a/discord_rss_bot/main.py +++ b/discord_rss_bot/main.py @@ -1,3 +1,31 @@ +""" +The main file for the discord-rss-bot. + +This file is used to start the bot. + +Functions: + check_feed() -> /check + POST - Update a feed. + crete_feed() -> /add + POST - Create a new feed. + favicon() -> /favicon.ico + GET - Return the favicon. + get_add() -> /add + GET - Page for adding a new feed. + get_feed() -> /feed + GET - Page for a single feed. + index() -> / + GET - index page. + remove_feed() -> /remove + POST - Remove a feed. + + create_list_of_webhooks() + Create a list with webhooks. + make_context_index() + Create the needed context for the index page. + startup() + Runs on startup. +""" import enum import sys from functools import cache @@ -60,7 +88,7 @@ def index(request: Request): This is the root of the website. Args: - request: + request: The request. Returns: HTMLResponse: The HTML response. @@ -188,10 +216,10 @@ async def create_feed(feed_url: str = Form(), webhook_dropdown: str = Form()): @app.get("/add", response_class=HTMLResponse) def get_add(request: Request): """ - This is the root of the website. + Page for adding a new feed. Args: - request: + request: The request. Returns: HTMLResponse: The HTML response. diff --git a/discord_rss_bot/settings.py b/discord_rss_bot/settings.py index a2afa6b..2b0ecb1 100644 --- a/discord_rss_bot/settings.py +++ b/discord_rss_bot/settings.py @@ -1,3 +1,21 @@ +"""This module contains functions for reading and writing settings and configuration files. + +Functions: + create_settings_file: + Create the settings file if it doesn't exist. + get_data_dir: + Path to the data directory. This is where the database file and config file are stored. + get_db_file: + Where we store the database file. + read_settings_file: + Read the settings file and return it as a dict. + +Variables: + data_directory: + The application directory, defaults to user_data_dir(). + logger: + The logger for this program. +""" import logging import os from pathlib import Path @@ -63,7 +81,7 @@ def get_db_file(custom_db_name: str = "db.sqlite") -> Path: return Path(db_file) -def _create_settings_file(settings_file) -> None: +def create_settings_file(settings_file) -> None: """Create the settings file if it doesn't exist.""" logger.debug(f"Settings file: {settings_file}") @@ -112,7 +130,7 @@ def read_settings_file(custom_settings_name: str = "settings.toml") -> TOMLDocum # Create the settings file if it doesn't exist if not os.path.exists(settings_file): - _create_settings_file(settings_file) + create_settings_file(settings_file) with open(settings_file, encoding="utf-8") as f: data = parse(f.read())