From 269ea6db08d0ca72edaa43dd0f882ad442c1088e Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 15 Sep 2024 18:55:32 -0400 Subject: [PATCH] docs: add docstrings --- stockbot-buyvm.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/stockbot-buyvm.py b/stockbot-buyvm.py index 3e17bee..d8bab9e 100644 --- a/stockbot-buyvm.py +++ b/stockbot-buyvm.py @@ -16,6 +16,15 @@ URLS = [ def get_url(url): + """ + Fetches a URL and returns its text content. + + Args: + url (str): The URL to fetch. + + Returns: + str: The text content of the page, or None if there was an error. + """ try: response = requests.get(url) response.raise_for_status() @@ -27,6 +36,18 @@ def get_url(url): def get_packages(html): + """ + Takes a string of HTML and extracts all the packages from it. + + Args: + html (str): The HTML to parse. + + Returns: + list: A list of packages, each represented as a dictionary with the following keys: + 'name' (str): The name of the package. + 'qty' (int): The current quantity of the package available. + 'url' (str): The URL to order the package from, or an empty string if the package is not available. + """ soup = BeautifulSoup(html, 'html.parser') packages = [] @@ -58,6 +79,20 @@ def load_config(filename): async def main(): + """ + Check BuyVM for available KVM slices and alert to a Matrix room if any are found. + + The following configuration options are supported: + + - `memory`: A list of integers specifying the memory quantities to check for. + Defaults to [512, 1, 2, 4], which corresponds to a price of $15.00 or less. + + The function will log in to the Matrix server specified in the configuration, + then check each URL in `URLS` for available KVM slices. If any are found, + it will send a message to the room specified in the configuration with the + package name and quantity, and a link to order. Finally, it will close the + Matrix session. + """ logger.info('checking buyvm stocks') config = load_config('config.json') bot = MatrixBot(config['matrix'])