docs: add docstrings

This commit is contained in:
agatha 2024-09-15 18:55:32 -04:00
parent 3c9795ac4f
commit 269ea6db08

View File

@ -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'])