From af86d4aa8f7bc4820a6c458a447855250eb0dc6c Mon Sep 17 00:00:00 2001 From: Djeex Date: Sat, 12 Jul 2025 11:19:55 +0000 Subject: [PATCH] Better default env var --- Dockerfile | 3 --- app/env_config.py | 7 ++++++- app/notifier.py | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3eb1582..9f36fd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,4 @@ COPY /app/ /app/ RUN pip install --no-cache-dir -r requirements.txt -ENV DISCORD_WEBHOOK_URL="https://example.com/webhook" \ - REFRESH_TIME="30" - CMD ["python", "main.py"] \ No newline at end of file diff --git a/app/env_config.py b/app/env_config.py index bc66402..164e9af 100644 --- a/app/env_config.py +++ b/app/env_config.py @@ -17,7 +17,7 @@ try: DISCORD_SERVER_NAME = os.environ.get('DISCORD_SERVER_NAME', 'Shared for free') API_URL_SKU = os.environ.get('API_URL_SKU', 'https://api.nvidia.partners/edge/product/search?page=1&limit=100&locale=fr-fr&Manufacturer=Nvidia') API_URL_STOCK = os.environ.get('API_URL_STOCK', 'https://api.store.nvidia.com/partner/v1/feinventory?locale=fr-fr&skus=') - REFRESH_TIME = int(os.environ['REFRESH_TIME']) + REFRESH_TIME = int(os.environ.get('REFRESH_TIME', 30)) TEST_MODE = os.environ.get('TEST_MODE', 'False').lower() == 'true' PRODUCT_URL = os.environ.get('PRODUCT_URL', 'https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&manufacturer=NVIDIA') DISCORD_ROLES = os.environ.get('DISCORD_ROLES') @@ -67,6 +67,10 @@ if match: else: wh_masked_url = "[Invalid webhook URL]" +# Test mode +if TEST_MODE: + logging.warning("🚧 Test mode is active. No real alerts will be sent.") + # HTTP headers HEADERS = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) " @@ -128,6 +132,7 @@ footer = loc["footer"] sku_description = loc["sku_description"] imminent_drop = loc["imminent_drop"] +# Logging logging.info(f"GPU: {PRODUCT_NAMES}") logging.info(f"Discord Webhook URL: {wh_masked_url}") logging.info(f"Discord Role Mention: {DISCORD_ROLES}") diff --git a/app/notifier.py b/app/notifier.py index aadcb86..724f225 100644 --- a/app/notifier.py +++ b/app/notifier.py @@ -10,6 +10,7 @@ from env_config import ( AVATAR = "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg" THUMBNAIL = "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/RTX5000.jpg" +# In stock def send_discord_notification(gpu_name, product_link, products_price): timestamp = int(time.time()) if TEST_MODE: @@ -45,6 +46,7 @@ def send_discord_notification(gpu_name, product_link, products_price): except Exception as e: logging.error(f"🚨 Error sending webhook: {e}") +# Out of stock def send_out_of_stock_notification(gpu_name, product_link, products_price): timestamp = int(time.time()) if TEST_MODE: @@ -76,6 +78,7 @@ def send_out_of_stock_notification(gpu_name, product_link, products_price): except Exception as e: logging.error(f"🚨 Error sending webhook: {e}") +# SKU change def send_sku_change_notification(gpu_name, old_sku, new_sku, product_link): timestamp = int(time.time()) if TEST_MODE: