diff --git a/README.md b/README.md index 5edd1a4..2511a8a 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,13 @@ services: restart: unless-stopped environment: # Minimal environment variables - - PRODUCT_NAMES= # Exact GPU name (e.g. "RTX 5080, RTX 5090") - - DISCORD_WEBHOOK_URL= # Your Discord webhook URL - - API_URL_SKU= # API listing the product for your country - - API_URL_STOCK= # API providing stock data for your country - - PRODUCT_URL= # GPU purchase URL for your country - - PYTHONUNBUFFERED=1 # Enables real-time log output + - PRODUCT_NAMES= # Exact GPU name (e.g. "RTX 5080, RTX 5090") + - DISCORD_WEBHOOK_URL= # Your Discord webhook URL + - DISCORD_NOTIFICATION_CURRENCY= # Set your country currency + - API_URL_SKU= # API listing the product for your country + - API_URL_STOCK= # API providing stock data for your country + - PRODUCT_URL= # GPU purchase URL for your country + - PYTHONUNBUFFERED=1 # Enables real-time log output ``` **Environment Variables:** @@ -69,6 +70,7 @@ services: |---------------------|-------------------------------------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------| | `PRODUCT_NAMES` | The exact GPU names you're searching for | `RTX 5080, RTX 5090` | | | `DISCORD_WEBHOOK_URL` | Your Discord webhook URL | A valid URL | | +| `DISCORD_NOTIFICATION_CURRENCY` | Your country currency | A text, e.g. `$`, `€`, `£`... | `€` | | `DISCORD_SERVER_NAME` | The name of your server, displayed in notification's footer | A text | Shared for free | | `DISCORD_NOTIFICATION_LANGUAGE` | Your language for notification's content | `bg`, `cs`, `da`, `de`, `el`, `en`, `es`, `et`, `fi`, `fr`, `ga`, `hr`, `hu`, `it`, `lt`, `lv`, `mt`, `nl`, `pl`, `pt`, `ro`, `sk`, `sl`, `sv` | `en` | | `DISCORD_ROLES` | List of Discord roles ID in the same order than `PRODUCT_NAMES` values, found in your discord server settings (with user profile developer mode enabled) | `<@&12345><@&6789>` | @everyone | @@ -151,6 +153,7 @@ git clone https://git.djeex.fr/Djeex/nvidia-stock-bot.git ```sh export DISCORD_WEBHOOK_URL="https://your_discord_url" +export DISCORD_NOTIFICATION_CURRENCY=€ export PRODUCT_NAMES=RTX 5080, RTX 5090 export DISCORD_ROLES=<@&12345>, <@&6789> export REFRESH_TIME="60" diff --git a/app/env_config.py b/app/env_config.py index 164e9af..00fbcf2 100644 --- a/app/env_config.py +++ b/app/env_config.py @@ -15,9 +15,10 @@ try: # Env variables DISCORD_WEBHOOK_URL = os.environ['DISCORD_WEBHOOK_URL'] 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.get('REFRESH_TIME', 30)) + DISCORD_NOTIFICATION_CURRENCY = os.environ.get('DISCORD_NOTIFICATION_CURRENCY') or '€' + API_URL_SKU = os.environ.get('API_URL_SKU') or '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') or 'https://api.store.nvidia.com/partner/v1/feinventory?locale=fr-fr&skus=' + REFRESH_TIME = int(os.environ.get('REFRESH_TIME') or 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') @@ -32,6 +33,9 @@ except ValueError: if not PRODUCT_NAMES: logging.error("❌ PRODUCT_NAMES is required but not defined.") sys.exit(1) +if not DISCORD_WEBHOOK_URL: + logging.error("❌ DISCORD_WEBHOOK_URL is required but not defined.") + sys.exit(1) PRODUCT_NAMES = [name.strip() for name in PRODUCT_NAMES.split(',')] @@ -52,10 +56,6 @@ else: sys.exit(1) DISCORD_ROLE_MAP[name] = role -if not DISCORD_WEBHOOK_URL: - logging.error("❌ DISCORD_WEBHOOK_URL is required but not defined.") - sys.exit(1) - # Masked webhook for display match = re.search(r'/(\d+)/(.*)', DISCORD_WEBHOOK_URL) if match: @@ -136,6 +136,7 @@ imminent_drop = loc["imminent_drop"] logging.info(f"GPU: {PRODUCT_NAMES}") logging.info(f"Discord Webhook URL: {wh_masked_url}") logging.info(f"Discord Role Mention: {DISCORD_ROLES}") +logging.info(f"Currency used for notifications: {DISCORD_NOTIFICATION_CURRENCY}") logging.info(f"API URL SKU: {API_URL_SKU}") logging.info(f"API URL Stock: {API_URL_STOCK}") logging.info(f"Product URL: {PRODUCT_URL}") diff --git a/app/notifier.py b/app/notifier.py index 724f225..b28d342 100644 --- a/app/notifier.py +++ b/app/notifier.py @@ -2,7 +2,7 @@ import time import logging import requests from env_config import ( - DISCORD_WEBHOOK_URL, DISCORD_SERVER_NAME, DISCORD_ROLE_MAP, TEST_MODE, + DISCORD_WEBHOOK_URL, DISCORD_SERVER_NAME, DISCORD_ROLE_MAP, TEST_MODE, DISCORD_NOTIFICATION_CURRENCY, in_stock_title, out_of_stock_title, sku_change_title, buy_now, price_label, time_label, footer, sku_description, imminent_drop ) @@ -13,6 +13,7 @@ THUMBNAIL = "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/ # In stock def send_discord_notification(gpu_name, product_link, products_price): timestamp = int(time.time()) + currency = DISCORD_NOTIFICATION_CURRENCY if TEST_MODE: logging.info(f"[TEST MODE] Notification: {gpu_name} available!") return @@ -23,7 +24,7 @@ def send_discord_notification(gpu_name, product_link, products_price): "thumbnail": {"url": THUMBNAIL}, "author": {"name": "Nvidia Founder Editions"}, "fields": [ - {"name": price_label, "value": f"`{products_price}€`", "inline": True}, + {"name": price_label, "value": f"`{currency}{products_price}`", "inline": True}, {"name": time_label, "value": f" ", "inline": True} ], "description": buy_now.format(product_link=product_link), diff --git a/docker/compose.yaml b/docker/compose.yaml index 095be85..19e3636 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -7,9 +7,10 @@ services: - .env environment: # Minimal environment variables - - PRODUCT_NAMES=${PRODUCT_NAMES} # Exact GPU name (e.g. "RTX 5080, RTX 5090") - - DISCORD_WEBHOOK_URL=${DISCORD_WEBHOOK_URL} # Your Discord webhook URL - - API_URL_SKU=${API_URL_SKU} # API listing the product for your country - - API_URL_STOCK=${API_URL_STOCK} # API providing stock data for your country - - PRODUCT_URL=${PRODUCT_URL} # GPU purchase URL for your country - - PYTHONUNBUFFERED=1 # Enables real-time log output \ No newline at end of file + - PRODUCT_NAMES= # Exact GPU name (e.g. "RTX 5080, RTX 5090") + - DISCORD_WEBHOOK_URL= # Your Discord webhook URL + - DISCORD_NOTIFICATION_CURRENCY= # Set your country currency + - API_URL_SKU= # API listing the product for your country + - API_URL_STOCK= # API providing stock data for your country + - PRODUCT_URL= # GPU purchase URL for your country + - PYTHONUNBUFFERED=1 # Enables real-time log output \ No newline at end of file