From 78763a173bec0ae4eae8f51006b37e1421c544a8 Mon Sep 17 00:00:00 2001 From: agatha Date: Sat, 2 Dec 2023 16:37:52 -0500 Subject: [PATCH] Add logging with loguru --- requirements.txt | 1 + stockbot-buyvm.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1f3e778..8e0da18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ beautifulsoup4 requests +loguru diff --git a/stockbot-buyvm.py b/stockbot-buyvm.py index b62f695..5060824 100644 --- a/stockbot-buyvm.py +++ b/stockbot-buyvm.py @@ -1,6 +1,7 @@ """buyvm stock checker""" import requests from bs4 import BeautifulSoup +from loguru import logger from config import DISCORD_WEBHOOK @@ -17,7 +18,7 @@ def send_notification(payload): try: requests.post(DISCORD_WEBHOOK, json=payload) except requests.RequestException as e: - print(f'error sending notification: {str(e)}') + logger.error(f'error sending notification: {str(e)}') def get_url(url): @@ -25,7 +26,7 @@ def get_url(url): response = requests.get(url) response.raise_for_status() except requests.RequestException as e: - print(f'error fetching {url}: {str(e)}') + logger.error(f'error fetching {url}: {str(e)}') return None return response.text @@ -58,12 +59,14 @@ def get_packages(html): def main(): + logger.info('checking buyvm stocks') for url in URLS: html = get_url(url) packages = get_packages(html) for package in packages: if package['qty'] > 0: + logger.info(f"{package['name']}: {package['qty']} in stock") send_notification({ "username": "stockbot-buyvm", "embeds": [