v3.0 - Multi GPU support #10
							
								
								
									
										58
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								README.md
									
									
									
									
									
								
							@@ -17,12 +17,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## 📌 Table of Contents
 | 
					## 📌 Table of Contents
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- [✨ Features](#features)
 | 
					- [✨ Features](#-features)
 | 
				
			||||||
- [🐳 Docker Installation without cloning the repo (quick)](#docker-installation-without-the-repo-quick)
 | 
					- [🐳 Docker Installation without cloning the repo (quick)](#-docker-installation-without-the-repo-quick)
 | 
				
			||||||
- [🐙 Docker Installation with the repo (developer)](#docker-installation-with-the-repo)
 | 
					- [🐙 Docker Installation with the repo (developer)](#-docker-installation-with-the-repo)
 | 
				
			||||||
- [🐍 Python Installation (developer)](#python-installation)
 | 
					- [🐍 Python Installation (developer)](#-python-installation)
 | 
				
			||||||
- [🖼️ Screenshots](#screenshots)
 | 
					- [🖼️ Screenshots](#-screenshots)
 | 
				
			||||||
- [🧑💻 Contributors](#contributors)
 | 
					- [🐞 Common issues](#-common-issues)
 | 
				
			||||||
 | 
					- [🧑💻 Contributors](#-contributors)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## ✨ Features
 | 
					## ✨ Features
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -51,8 +52,13 @@ services:
 | 
				
			|||||||
    container_name: nvidia-stock-bot
 | 
					    container_name: nvidia-stock-bot
 | 
				
			||||||
    restart: unless-stopped
 | 
					    restart: unless-stopped
 | 
				
			||||||
    environment:
 | 
					    environment:
 | 
				
			||||||
 | 
					      - PRODUCT_NAMES=       # Exact GPU name (e.g. "RTX 5080, RTX 5090")
 | 
				
			||||||
 | 
					      - DISCORD_ROLES=       # List of Discord roles ID (e.g. "<@&12345>, <@&6789>"), in the same order than PRODUCT_NAMES values. @everyone by default.
 | 
				
			||||||
      - DISCORD_WEBHOOK_URL= # Your Discord webhook URL
 | 
					      - DISCORD_WEBHOOK_URL= # Your Discord webhook URL
 | 
				
			||||||
      - PRODUCT_NAME=        # Exact GPU name like "RTX 5080"
 | 
					      - API_URL_SKU=         # API listing the product
 | 
				
			||||||
 | 
					      - API_URL_STOCK=       # API providing stock data
 | 
				
			||||||
 | 
					      - PRODUCT_URL=         # GPU purchase URL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      - PYTHONUNBUFFERED=1   # Enables real-time log output
 | 
					      - PYTHONUNBUFFERED=1   # Enables real-time log output
 | 
				
			||||||
    command: python nvidia-stock-bot.py
 | 
					    command: python nvidia-stock-bot.py
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
@@ -61,14 +67,15 @@ services:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
| Variable            | Description                                     | Possible Values                                                  | Default Value                                                                                              |
 | 
					| Variable            | Description                                     | Possible Values                                                  | Default Value                                                                                              |
 | 
				
			||||||
|---------------------|-------------------------------------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
 | 
					|---------------------|-------------------------------------------------|------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
 | 
				
			||||||
| DISCORD_WEBHOOK_URL | Your Discord webhook URL                        | A valid URL                                                      |                                                                                                             |
 | 
					| `DISCORD_WEBHOOK_URL` | Your Discord webhook URL                        | A valid URL                                                      |                                                                                                             |
 | 
				
			||||||
| REFRESH_TIME        | Script refresh interval in seconds              | `60`, `30`, etc.                                                 | `30`                                                                                                        |
 | 
					| `PRODUCT_NAMES`        | The exact GPU names you're searching for         | `RTX 5080, RTX 5090`                             |                                                                                                             |
 | 
				
			||||||
| API_URL_SKU         | API listing the product                         | A URL                                                            | `https://api.nvidia.partners/edge/product/search?page=1&limit=100&locale=fr-fr&Manufacturer=Nvidia`         |
 | 
					| `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                                                                                                            |
 | 
				
			||||||
| API_URL_STOCK       | API providing stock data                        | A URL                                                            | `https://api.store.nvidia.com/partner/v1/feinventory?locale=fr-fr&skus=`                                    |
 | 
					| `REFRESH_TIME`        | Script refresh interval in seconds              | `60`, `30`, etc.                                                 | `30`                                                                                                        |
 | 
				
			||||||
| PRODUCT_URL         | GPU purchase URL                                | A URL                                                            | `https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&manufacturer=NVIDIA` |
 | 
					| `API_URL_SKU`         | API listing the product                         | A URL. API url can change over time. For now, you can use the default one and change the `locale` parameter to yours (e.g. `locale=en-gb`)                                                            | `https://api.nvidia.partners/edge/product/search?page=1&limit=100&locale=fr-fr&Manufacturer=Nvidia`         |
 | 
				
			||||||
| PRODUCT_NAME        | The exact GPU name you're searching for         | `RTX 5090`, `RTX 5080`, `RTX 5070`                               |                                                                                                             |
 | 
					| `API_URL_STOCK`       | API providing stock data                        | A URL. API url can change over time. For now, you can use the default one and change the `locale` parameter to yours (e.g. `locale=en-gb`)                                                                  | `https://api.store.nvidia.com/partner/v1/feinventory?locale=fr-fr&skus=`                                    |
 | 
				
			||||||
| TEST_MODE           | For testing without sending notifications       | `True`, `False`                                                  | `False`                                                                                                     |
 | 
					| `PRODUCT_URL`         | GPU purchase URL. There isn't any direct link workinf right now, so put the generic marketplace url listing all FE products                              | A URL. API url can change over time. For now, you can use the default one and change the locale parameter to yours (e.g. `/en-gb/`)                                                                  | `https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&manufacturer=NVIDIA` |
 | 
				
			||||||
| PYTHONUNBUFFERED    | Enables real-time log output                    | `1`, `0`                                                         | `1`                                                                                                         |
 | 
					| `TEST_MODE`           | For testing without sending notifications       | `True`, `False`                                                  | `False`                                                                                                     |
 | 
				
			||||||
 | 
					| `PYTHONUNBUFFERED`    | Enables real-time log output                    | `1`, `0`                                                         | `1`                                                                                                         |
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**Run the image**
 | 
					**Run the image**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -132,24 +139,24 @@ Instructions to directly run the Python script. Note: the bot stops when you clo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
**Configuration**
 | 
					**Configuration**
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Create a virtual environment (e.g., `python3 -m venv env_name`)
 | 
					- Clone the repo:
 | 
				
			||||||
- Create and navigate into a folder
 | 
					 | 
				
			||||||
- Download the Python script:
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
curl -o nvidia-stock-bot.py -# https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/nvidia-stock-bot.py
 | 
					git clone https://git.djeex.fr/Djeex/nvidia-stock-bot.git
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					- Navigate to `nvidia-stock-bot` and create a virtual environment (e.g., `python3 -m venv env_name`)
 | 
				
			||||||
- Export the environment variables with your webhook and refresh time:
 | 
					- Export the environment variables with your webhook and refresh time, for exemple:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```sh
 | 
					```sh
 | 
				
			||||||
export DISCORD_WEBHOOK_URL="https://your_discord_url"
 | 
					export DISCORD_WEBHOOK_URL="https://your_discord_url"
 | 
				
			||||||
 | 
					export PRODUCT_NAMES=RTX 5080, RTX 5090
 | 
				
			||||||
 | 
					export DISCORD_ROLES=<@&12345>, <@&6789>
 | 
				
			||||||
export REFRESH_TIME="60"
 | 
					export REFRESH_TIME="60"
 | 
				
			||||||
export API_URL_SKU="https://api.nvidia.partners/edge/product/search?page=1&limit=100&locale=fr-fr&Manufacturer=Nvidia&gpu=RTX%205080"
 | 
					export API_URL_SKU="https://api.nvidia.partners/edge/product/search?page=1&limit=100&locale=fr-fr&Manufacturer=Nvidia&gpu=RTX%205080"
 | 
				
			||||||
export API_URL_STOCK="https://api.store.nvidia.com/partner/v1/feinventory?locale=fr-fr&skus="
 | 
					export API_URL_STOCK="https://api.store.nvidia.com/partner/v1/feinventory?locale=fr-fr&skus="
 | 
				
			||||||
export PRODUCT_URL="https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&gpu=RTX%205080&manufacturer=NVIDIA"
 | 
					export PRODUCT_URL="https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&gpu=RTX%205080&manufacturer=NVIDIA"
 | 
				
			||||||
export PRODUCT_NAME="RTX 5080"
 | 
					 | 
				
			||||||
export TEST_MODE=false
 | 
					export TEST_MODE=false
 | 
				
			||||||
 | 
					export PYTHONUNBUFFERED=1
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Run the script
 | 
					- Run the script
 | 
				
			||||||
@@ -164,6 +171,13 @@ python nvidia-stock-bot.py
 | 
				
			|||||||
  <img src="https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/nvidia-stock-bot-discord.png" alt="Nvidia Stock Bot - screenshots">
 | 
					  <img src="https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/nvidia-stock-bot-discord.png" alt="Nvidia Stock Bot - screenshots">
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 🐞 Common issues
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Error when trying to reach product API url :
 | 
				
			||||||
 | 
					- `API_SKU_URL` may be wrong
 | 
				
			||||||
 | 
					- Your IP may be blacklisted by nvidia. Try to use a VPN.
 | 
				
			||||||
 | 
					- nvidia API may be down
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 🧑💻 Contributors
 | 
					## 🧑💻 Contributors
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Thanks for their contributions:
 | 
					Thanks for their contributions:
 | 
				
			||||||
 
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 170 KiB After Width: | Height: | Size: 95 KiB  | 
@@ -20,15 +20,36 @@ try:
 | 
				
			|||||||
    REFRESH_TIME = int(os.environ.get('REFRESH_TIME'))
 | 
					    REFRESH_TIME = int(os.environ.get('REFRESH_TIME'))
 | 
				
			||||||
    TEST_MODE = os.environ.get('TEST_MODE', 'False').lower() == 'true'
 | 
					    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')
 | 
					    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')
 | 
				
			||||||
    PRODUCT_NAME = os.environ.get('PRODUCT_NAME')
 | 
					    DISCORD_ROLES = os.environ.get('DISCORD_ROLES')
 | 
				
			||||||
 | 
					    PRODUCT_NAMES = os.environ.get('PRODUCT_NAMES')
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Error logging
 | 
					    if not PRODUCT_NAMES:
 | 
				
			||||||
    if not DISCORD_WEBHOOK_URL:
 | 
					        logging.error("❌ PRODUCT_NAMES is required but not defined.")
 | 
				
			||||||
        logging.error("❌ DISCORD_WEBHOOK_URL is required but not defined.")
 | 
					 | 
				
			||||||
        exit(1)
 | 
					        exit(1)
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    if not PRODUCT_NAME:
 | 
					    PRODUCT_NAMES = [name.strip() for name in PRODUCT_NAMES.split(',')]
 | 
				
			||||||
        logging.error("❌ PRODUCT_NAME is required but not defined.")
 | 
					    DISCORD_ROLE_MAP = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if not DISCORD_ROLES or not DISCORD_ROLES.strip():
 | 
				
			||||||
 | 
					        logging.warning("⚠️ DISCORD_ROLES not defined or empty. Defaulting all roles to @everyone.")
 | 
				
			||||||
 | 
					        for name in PRODUCT_NAMES:
 | 
				
			||||||
 | 
					            DISCORD_ROLE_MAP[name] = '@everyone'
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        roles = [r.strip() if r.strip() else '@everyone' for r in DISCORD_ROLES.split(',')]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if len(roles) != len(PRODUCT_NAMES):
 | 
				
			||||||
 | 
					            logging.error("❌ The number of DISCORD_ROLES must match PRODUCT_NAMES.")
 | 
				
			||||||
 | 
					            exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for name, role in zip(PRODUCT_NAMES, roles):
 | 
				
			||||||
 | 
					            if role != '@everyone' and not re.match(r'^<@&\d{17,20}>$', role):
 | 
				
			||||||
 | 
					                logging.error(f"❌ Invalid DISCORD_ROLE format for {name}: {role}")
 | 
				
			||||||
 | 
					                exit(1)
 | 
				
			||||||
 | 
					            DISCORD_ROLE_MAP[name] = role
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if not DISCORD_WEBHOOK_URL:
 | 
				
			||||||
 | 
					        logging.error("❌ DISCORD_WEBHOOK_URL is required but not defined.")
 | 
				
			||||||
        exit(1)
 | 
					        exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Regex to extract ID and token
 | 
					    # Regex to extract ID and token
 | 
				
			||||||
@@ -55,8 +76,9 @@ except ValueError:
 | 
				
			|||||||
    exit(1)
 | 
					    exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Display URLs and configurations
 | 
					# Display URLs and configurations
 | 
				
			||||||
logging.info(f"GPU: {PRODUCT_NAME}")
 | 
					logging.info(f"GPU: {PRODUCT_NAMES}")
 | 
				
			||||||
logging.info(f"Discord Webhook URL: {wh_masked_url}")
 | 
					logging.info(f"Discord Webhook URL: {wh_masked_url}")
 | 
				
			||||||
 | 
					logging.info(f"Discord Role Mention: {DISCORD_ROLES}")
 | 
				
			||||||
logging.info(f"API URL SKU: {API_URL_SKU}")
 | 
					logging.info(f"API URL SKU: {API_URL_SKU}")
 | 
				
			||||||
logging.info(f"API URL Stock: {API_URL_STOCK}")
 | 
					logging.info(f"API URL Stock: {API_URL_STOCK}")
 | 
				
			||||||
logging.info(f"Product URL: {PRODUCT_URL}")
 | 
					logging.info(f"Product URL: {PRODUCT_URL}")
 | 
				
			||||||
@@ -87,12 +109,9 @@ session = requests.Session()
 | 
				
			|||||||
retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
 | 
					retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
 | 
				
			||||||
session.mount('https://', HTTPAdapter(max_retries=retries))
 | 
					session.mount('https://', HTTPAdapter(max_retries=retries))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Store stock status
 | 
					last_sku_dict = {}
 | 
				
			||||||
global_stock_status = {}
 | 
					global_stock_status_dict = {}
 | 
				
			||||||
 | 
					first_run_dict = {name: True for name in PRODUCT_NAMES}
 | 
				
			||||||
# Store the last known SKU
 | 
					 | 
				
			||||||
last_sku = None
 | 
					 | 
				
			||||||
first_run = True  # Before calling check_rtx_50_founders
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Discord notifications
 | 
					# Discord notifications
 | 
				
			||||||
def send_discord_notification(gpu_name: str, product_link: str, products_price: str):
 | 
					def send_discord_notification(gpu_name: str, product_link: str, products_price: str):
 | 
				
			||||||
@@ -105,7 +124,7 @@ def send_discord_notification(gpu_name: str, product_link: str, products_price:
 | 
				
			|||||||
        return
 | 
					        return
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    embed = {
 | 
					    embed = {
 | 
				
			||||||
        "title": f"🚀 {PRODUCT_NAME} IN STOCK!",
 | 
					        "title": f"🚀 {gpu_name} IN STOCK!",
 | 
				
			||||||
        "color": 3066993,
 | 
					        "color": 3066993,
 | 
				
			||||||
        "thumbnail": {
 | 
					        "thumbnail": {
 | 
				
			||||||
            "url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/RTX5000.jpg"
 | 
					            "url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/RTX5000.jpg"
 | 
				
			||||||
@@ -133,7 +152,14 @@ def send_discord_notification(gpu_name: str, product_link: str, products_price:
 | 
				
			|||||||
            "icon_url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg"
 | 
					            "icon_url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg"
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    payload = {"content": "@everyone", "username": "NviBot", "avatar_url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg", "embeds": [embed]}
 | 
					
 | 
				
			||||||
 | 
					    payload = {
 | 
				
			||||||
 | 
					        "content": f"{DISCORD_ROLE_MAP.get(gpu_name, '@everyone')}",
 | 
				
			||||||
 | 
					        "username": "NviBot",
 | 
				
			||||||
 | 
					        "avatar_url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg",
 | 
				
			||||||
 | 
					        "embeds": [embed]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        response = requests.post(DISCORD_WEBHOOK_URL, json=payload)
 | 
					        response = requests.post(DISCORD_WEBHOOK_URL, json=payload)
 | 
				
			||||||
        if response.status_code == 204:
 | 
					        if response.status_code == 204:
 | 
				
			||||||
@@ -153,7 +179,7 @@ def send_out_of_stock_notification(gpu_name: str, product_link: str, products_pr
 | 
				
			|||||||
        return
 | 
					        return
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    embed = {
 | 
					    embed = {
 | 
				
			||||||
        "title": f"❌ {PRODUCT_NAME} is out of stock",
 | 
					        "title": f"❌ {gpu_name} is out of stock",
 | 
				
			||||||
        "color": 15158332,  # Red for out of stock
 | 
					        "color": 15158332,  # Red for out of stock
 | 
				
			||||||
        "thumbnail": {
 | 
					        "thumbnail": {
 | 
				
			||||||
            "url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/RTX5000.jpg"
 | 
					            "url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/RTX5000.jpg"
 | 
				
			||||||
@@ -186,7 +212,7 @@ def send_out_of_stock_notification(gpu_name: str, product_link: str, products_pr
 | 
				
			|||||||
    except Exception as e:
 | 
					    except Exception as e:
 | 
				
			||||||
        logging.error(f"🚨 Error sending webhook: {e}")
 | 
					        logging.error(f"🚨 Error sending webhook: {e}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def send_sku_change_notification(old_sku: str, new_sku: str, product_link: str):
 | 
					def send_sku_change_notification(gpu_name: str, old_sku: str, new_sku: str, product_link: str):
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    # Get current UNIX timestamp
 | 
					    # Get current UNIX timestamp
 | 
				
			||||||
    timestamp_unix = int(time.time())
 | 
					    timestamp_unix = int(time.time())
 | 
				
			||||||
@@ -196,7 +222,7 @@ def send_sku_change_notification(old_sku: str, new_sku: str, product_link: str):
 | 
				
			|||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    embed = {
 | 
					    embed = {
 | 
				
			||||||
        "title": f"🔄 {PRODUCT_NAME} SKU change detected",
 | 
					        "title": f"🔄 {gpu_name} SKU change detected",
 | 
				
			||||||
        "url": f"{product_link}",
 | 
					        "url": f"{product_link}",
 | 
				
			||||||
        "description": f"**Old SKU** : `{old_sku}`\n**New SKU** : `{new_sku}`",
 | 
					        "description": f"**Old SKU** : `{old_sku}`\n**New SKU** : `{new_sku}`",
 | 
				
			||||||
        "color": 16776960,  # Yellow
 | 
					        "color": 16776960,  # Yellow
 | 
				
			||||||
@@ -216,7 +242,7 @@ def send_sku_change_notification(old_sku: str, new_sku: str, product_link: str):
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    payload = {
 | 
					    payload = {
 | 
				
			||||||
        "content": "@everyone ⚠️ Possible imminent drop!",
 | 
					        "content": f"{DISCORD_ROLE_MAP.get(gpu_name, '@everyone')} ⚠️ Possible imminent drop!",
 | 
				
			||||||
        "username": "NviBot",
 | 
					        "username": "NviBot",
 | 
				
			||||||
        "avatar_url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg",
 | 
					        "avatar_url": "https://git.djeex.fr/Djeex/nvidia-stock-bot/raw/branch/main/assets/img/ds_wh_pp.jpg",
 | 
				
			||||||
        "embeds": [embed]
 | 
					        "embeds": [embed]
 | 
				
			||||||
@@ -233,9 +259,8 @@ def send_sku_change_notification(old_sku: str, new_sku: str, product_link: str):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
# Stock search
 | 
					# Stock search
 | 
				
			||||||
def check_rtx_50_founders():
 | 
					def check_rtx_50_founders():
 | 
				
			||||||
    global global_stock_status, last_sku, first_run
 | 
					    global last_sku_dict, global_stock_status_dict, first_run_dict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Call product API to retrieve SKU and UPC
 | 
					 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        response = session.get(API_URL_SKU, headers=HEADERS, timeout=10)
 | 
					        response = session.get(API_URL_SKU, headers=HEADERS, timeout=10)
 | 
				
			||||||
        logging.info(f"SKU API response: {response.status_code}")
 | 
					        logging.info(f"SKU API response: {response.status_code}")
 | 
				
			||||||
@@ -245,96 +270,90 @@ def check_rtx_50_founders():
 | 
				
			|||||||
        logging.error(f"SKU API error: {e}")
 | 
					        logging.error(f"SKU API error: {e}")
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   # Look for product whose GPU matches PRODUCT_NAME
 | 
					    # All available products
 | 
				
			||||||
    product_details = None
 | 
					    all_products = data['searchedProducts']['productDetails']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for p in data['searchedProducts']['productDetails']:
 | 
					    for product_name in PRODUCT_NAMES:
 | 
				
			||||||
        gpu_name = p.get("gpu", "").strip()
 | 
					        product_details = None
 | 
				
			||||||
 | 
					        for p in all_products:
 | 
				
			||||||
 | 
					            if p.get("gpu", "").strip() == product_name:
 | 
				
			||||||
 | 
					                product_details = p
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # If the GPU matches exactly PRODUCT_NAME
 | 
					        if not product_details:
 | 
				
			||||||
        if gpu_name == PRODUCT_NAME.strip():
 | 
					            logging.warning(f"⚠️ No product with GPU '{product_name}' found.")
 | 
				
			||||||
            product_details = p
 | 
					            continue
 | 
				
			||||||
            break  # Exit as soon as the correct product is found
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not product_details:
 | 
					        product_sku = product_details['productSKU']
 | 
				
			||||||
        logging.warning(f"⚠️ No product with GPU '{PRODUCT_NAME}' found.")
 | 
					        product_upc = product_details.get('productUPC', "")
 | 
				
			||||||
        return
 | 
					        if not isinstance(product_upc, list):
 | 
				
			||||||
 | 
					            product_upc = [product_upc]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Retrieve the SKU for the found GPU
 | 
					        # Check SKU change
 | 
				
			||||||
    product_sku = product_details['productSKU']
 | 
					        old_sku = last_sku_dict.get(product_name)
 | 
				
			||||||
    product_upc = product_details.get('productUPC', "")
 | 
					        if old_sku and old_sku != product_sku and not first_run_dict[product_name]:
 | 
				
			||||||
 | 
					            logging.warning(f"⚠️ SKU changed for {product_name}: {old_sku} → {product_sku}")
 | 
				
			||||||
 | 
					            send_sku_change_notification(product_name, old_sku, product_sku, PRODUCT_URL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Check if this is the first execution
 | 
					        last_sku_dict[product_name] = product_sku
 | 
				
			||||||
    if last_sku is not None and product_sku != last_sku:
 | 
					        first_run_dict[product_name] = False
 | 
				
			||||||
        if not first_run:  # Prevent sending notification on first run
 | 
					 | 
				
			||||||
            product_link = PRODUCT_URL
 | 
					 | 
				
			||||||
            logging.warning(f"⚠️ SKU changed: {last_sku} → {product_sku}")
 | 
					 | 
				
			||||||
            send_sku_change_notification(last_sku, product_sku, product_link)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Update stored SKU
 | 
					        # Stock check
 | 
				
			||||||
    last_sku = product_sku
 | 
					        api_stock_url = API_URL_STOCK + product_sku
 | 
				
			||||||
    first_run = False  # Disable first-run protection
 | 
					        logging.info(f"[{product_name}] Checking stock: {api_stock_url}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not isinstance(product_upc, list):
 | 
					        try:
 | 
				
			||||||
        product_upc = [product_upc]
 | 
					            response = session.get(api_stock_url, headers=HEADERS, timeout=10)
 | 
				
			||||||
 | 
					            logging.info(f"[{product_name}] Stock API response: {response.status_code}")
 | 
				
			||||||
 | 
					            response.raise_for_status()
 | 
				
			||||||
 | 
					            stock_data = response.json()
 | 
				
			||||||
 | 
					        except requests.exceptions.RequestException as e:
 | 
				
			||||||
 | 
					            logging.error(f"Stock API error: {e}")
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # Build stock API URL and call to check status
 | 
					        products = stock_data.get("listMap", [])
 | 
				
			||||||
    API_URL = API_URL_STOCK + product_sku
 | 
					        products_price = "Price not available"
 | 
				
			||||||
    logging.info(f"Stock API URL called: {API_URL}")
 | 
					        if isinstance(products, list) and len(products) > 0:
 | 
				
			||||||
    
 | 
					            for p in products:
 | 
				
			||||||
    try:
 | 
					                price = p.get("price", 'Price not available')
 | 
				
			||||||
        response = session.get(API_URL, headers=HEADERS, timeout=10)
 | 
					                if price != 'Price not available':
 | 
				
			||||||
        logging.info(f"Stock API response: {response.status_code}")  
 | 
					                    products_price = price
 | 
				
			||||||
        response.raise_for_status()
 | 
					                    break
 | 
				
			||||||
        data = response.json()
 | 
					 | 
				
			||||||
    except requests.exceptions.RequestException as e:
 | 
					 | 
				
			||||||
        logging.error(f"Stock API error: {e}")
 | 
					 | 
				
			||||||
        return
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    products = data.get("listMap", [])
 | 
					 | 
				
			||||||
    products_price = 'Price not available'  # Default value
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Check product list and retrieve price
 | 
					 | 
				
			||||||
    if isinstance(products, list) and len(products) > 0:
 | 
					 | 
				
			||||||
        for product in products:
 | 
					 | 
				
			||||||
            price = product.get("price", 'Price not available')
 | 
					 | 
				
			||||||
            if price != 'Price not available':
 | 
					 | 
				
			||||||
                products_price = price  # Use found price
 | 
					 | 
				
			||||||
                break  # Stop at first found price
 | 
					 | 
				
			||||||
    else:
 | 
					 | 
				
			||||||
        logging.error("Product list is empty or malformed.")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    found_in_stock = set()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # Check status and send notifications accordingly
 | 
					 | 
				
			||||||
    for p in products:
 | 
					 | 
				
			||||||
        gpu_name = p.get("fe_sku", "").upper()
 | 
					 | 
				
			||||||
        is_active = p.get("is_active") == "true"
 | 
					 | 
				
			||||||
        if is_active and any(target.upper() in gpu_name for target in product_upc):
 | 
					 | 
				
			||||||
            found_in_stock.add(gpu_name)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    for gpu in product_upc:
 | 
					 | 
				
			||||||
        gpu_upper = gpu.upper()
 | 
					 | 
				
			||||||
        currently_in_stock = gpu_upper in found_in_stock
 | 
					 | 
				
			||||||
        previously_in_stock = global_stock_status.get(gpu_upper, False)
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        if currently_in_stock and not previously_in_stock:
 | 
					 | 
				
			||||||
            product_link = PRODUCT_URL
 | 
					 | 
				
			||||||
            send_discord_notification(gpu_upper, product_link, products_price)
 | 
					 | 
				
			||||||
            global_stock_status[gpu_upper] = True
 | 
					 | 
				
			||||||
            logging.info(f"{gpu} is now in stock!")
 | 
					 | 
				
			||||||
        elif not currently_in_stock and previously_in_stock:
 | 
					 | 
				
			||||||
            product_link = PRODUCT_URL
 | 
					 | 
				
			||||||
            send_out_of_stock_notification(gpu_upper, product_link, products_price)
 | 
					 | 
				
			||||||
            global_stock_status[gpu_upper] = False
 | 
					 | 
				
			||||||
            logging.info(f"{gpu} is no longer in stock.")
 | 
					 | 
				
			||||||
        elif currently_in_stock and previously_in_stock:
 | 
					 | 
				
			||||||
            logging.info(f"{gpu} is currently in stock.")
 | 
					 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            logging.info(f"{gpu} is currently out of stock.")
 | 
					            logging.error(f"[{product_name}] Product list is empty or malformed.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        found_in_stock = set()
 | 
				
			||||||
 | 
					        for p in products:
 | 
				
			||||||
 | 
					            gpu_name = p.get("fe_sku", "").upper()
 | 
				
			||||||
 | 
					            is_active = p.get("is_active") == "true"
 | 
				
			||||||
 | 
					            if is_active and any(upc.upper() in gpu_name for upc in product_upc):
 | 
				
			||||||
 | 
					                found_in_stock.add(gpu_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for upc in product_upc:
 | 
				
			||||||
 | 
					            upc_upper = upc.upper()
 | 
				
			||||||
 | 
					            currently_in_stock = upc_upper in found_in_stock
 | 
				
			||||||
 | 
					            previously_in_stock = global_stock_status_dict.get((product_name, upc_upper), False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if currently_in_stock and not previously_in_stock:
 | 
				
			||||||
 | 
					                send_discord_notification(product_name, PRODUCT_URL, products_price)
 | 
				
			||||||
 | 
					                global_stock_status_dict[(product_name, upc_upper)] = True
 | 
				
			||||||
 | 
					                logging.info(f"[{product_name}] {upc} is now in stock!")
 | 
				
			||||||
 | 
					            elif not currently_in_stock and previously_in_stock:
 | 
				
			||||||
 | 
					                send_out_of_stock_notification(product_name, PRODUCT_URL, products_price)
 | 
				
			||||||
 | 
					                global_stock_status_dict[(product_name, upc_upper)] = False
 | 
				
			||||||
 | 
					                logging.info(f"[{product_name}] {upc} is now out of stock.")
 | 
				
			||||||
 | 
					            elif currently_in_stock:
 | 
				
			||||||
 | 
					                logging.info(f"[{product_name}] {upc} still in stock.")
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                logging.info(f"[{product_name}] {upc} still out of stock.")
 | 
				
			||||||
# Loop
 | 
					# Loop
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    while True:
 | 
					    try:
 | 
				
			||||||
        check_rtx_50_founders()
 | 
					        while True:
 | 
				
			||||||
        time.sleep(REFRESH_TIME)
 | 
					            check_rtx_50_founders()
 | 
				
			||||||
 | 
					            time.sleep(REFRESH_TIME)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # Gracefully shut down        
 | 
				
			||||||
 | 
					    except KeyboardInterrupt:
 | 
				
			||||||
 | 
					        logging.info("🛑 Script interrupted by user. Exiting gracefully.")
 | 
				
			||||||
 | 
					        exit(0)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user