Compare commits
6 Commits
50a9c1f827
...
v3.3.1
Author | SHA1 | Date | |
---|---|---|---|
3ba8c86b53 | |||
c5a280d911 | |||
1b15946a55 | |||
af86d4aa8f | |||
f2b5b184ea | |||
70b723b781 |
@ -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"]
|
15
README.md
15
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"
|
||||
|
@ -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['REFRESH_TIME'])
|
||||
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:
|
||||
@ -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,9 +132,11 @@ 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}")
|
||||
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}")
|
||||
|
@ -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
|
||||
)
|
||||
@ -10,8 +10,10 @@ 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())
|
||||
currency = DISCORD_NOTIFICATION_CURRENCY
|
||||
if TEST_MODE:
|
||||
logging.info(f"[TEST MODE] Notification: {gpu_name} available!")
|
||||
return
|
||||
@ -22,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"<t:{timestamp}:d> <t:{timestamp}:T>", "inline": True}
|
||||
],
|
||||
"description": buy_now.format(product_link=product_link),
|
||||
@ -45,6 +47,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 +79,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:
|
||||
|
@ -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
|
||||
- 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
|
Reference in New Issue
Block a user