Fixed discord embed
This commit is contained in:
parent
f59890c7e5
commit
5487e0f7f8
@ -67,7 +67,7 @@ Vous trouverez-ci dessous les instructions pour configurer le conteneur avec not
|
|||||||
version: "3.8"
|
version: "3.8"
|
||||||
services:
|
services:
|
||||||
nvidia-stock-bot:
|
nvidia-stock-bot:
|
||||||
image: git.djeex.fr/djeex/nvidia-stock-bot:7
|
image: git.djeex.fr/djeex/nvidia-stock-bot:8
|
||||||
container_name: nvidia-stock-bot
|
container_name: nvidia-stock-bot
|
||||||
restart: always # Le conteneur redémarrera automatiquement en cas d'échec
|
restart: always # Le conteneur redémarrera automatiquement en cas d'échec
|
||||||
environment:
|
environment:
|
||||||
|
@ -51,26 +51,37 @@ HEADERS = {
|
|||||||
"Sec-GPC": "1",
|
"Sec-GPC": "1",
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dictionnaire stockant l'état de stock pour chaque GPU.
|
# Dictionnaire stockant l'état de stock
|
||||||
stock_status = {gpu.upper(): False for gpu in GPU_TARGETS}
|
stock_status = {gpu.upper(): False for gpu in GPU_TARGETS}
|
||||||
|
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
|
|
||||||
|
def send_discord_notification(gpu_name: str, product_link: str):
|
||||||
def send_discord_notification(message: str):
|
"""Envoie une notification Discord avec un embed via un webhook."""
|
||||||
"""Envoie un message sur un salon Discord via un webhook."""
|
embed = {
|
||||||
payload = {
|
"title": f"🚀 {gpu_name} en stock !",
|
||||||
"content": message
|
"description": f":point_right: **[Achetez ici](https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&gpu=RTX%205090,RTX%205080)**",
|
||||||
|
"color": 3066993, # Couleur verte
|
||||||
|
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime()),
|
||||||
|
#"thumbnail": {
|
||||||
|
# "url": "https://www.nvidia.com/content/dam/en-zz/Solutions/geforce/graphic-cards/50-series/rtx-5090/geforce-rtx-5090-learn-more-og-1200x630.jpg"
|
||||||
|
#}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"content": "@everyone",
|
||||||
|
"username": "Nvidia Bot",
|
||||||
|
"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:
|
||||||
logging.info("Notification envoyée sur Discord.")
|
logging.info("✅ Embed envoyé sur Discord.")
|
||||||
else:
|
else:
|
||||||
logging.error(f"Échec de l'envoi du webhook : {response.status_code} - {response.text}")
|
logging.error(f"❌ Erreur d'envoi du webhook : {response.status_code} - {response.text}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Erreur lors de l'appel au webhook Discord : {e}")
|
logging.error(f"🚨 Erreur lors de l'envoi du webhook : {e}")
|
||||||
|
|
||||||
|
|
||||||
def check_rtx_50_founders():
|
def check_rtx_50_founders():
|
||||||
"""Vérifie l'état de stock des GPU Founders Edition et notifie Discord si un GPU repasse en stock."""
|
"""Vérifie l'état de stock des GPU Founders Edition et notifie Discord si un GPU repasse en stock."""
|
||||||
@ -79,12 +90,8 @@ def check_rtx_50_founders():
|
|||||||
logging.info(f"Réponse de l'API : {response.status_code}")
|
logging.info(f"Réponse de l'API : {response.status_code}")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
except requests.exceptions.RequestException as e:
|
||||||
except requests.exceptions.ReadTimeout:
|
logging.error(f"Erreur lors de l'appel API : {e}")
|
||||||
logging.info("Time-out lors de l'appel API.")
|
|
||||||
return
|
|
||||||
except Exception as e:
|
|
||||||
logging.info(f"Erreur lors de l'appel API : {e}")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
products = data.get("searchedProducts", {}).get("productDetails", [])
|
products = data.get("searchedProducts", {}).get("productDetails", [])
|
||||||
@ -92,11 +99,11 @@ def check_rtx_50_founders():
|
|||||||
|
|
||||||
for p in products:
|
for p in products:
|
||||||
gpu_name = p.get("gpu", "").upper()
|
gpu_name = p.get("gpu", "").upper()
|
||||||
is_founder = p.get("isFounderEdition") is True
|
#is_founder = p.get("isFounderEdition") is True
|
||||||
is_nvidia = (p.get("manufacturer") == "NVIDIA")
|
#is_nvidia = (p.get("manufacturer") == "NVIDIA")
|
||||||
is_buy_now = (p.get("prdStatus") != "out_of_stock")
|
is_buy_now = (p.get("prdStatus") != "out_of_stock")
|
||||||
|
|
||||||
if is_founder and is_nvidia and is_buy_now:
|
if is_buy_now:
|
||||||
if any(target.upper() in gpu_name for target in GPU_TARGETS):
|
if any(target.upper() in gpu_name for target in GPU_TARGETS):
|
||||||
found_in_stock.add(gpu_name)
|
found_in_stock.add(gpu_name)
|
||||||
|
|
||||||
@ -111,13 +118,7 @@ def check_rtx_50_founders():
|
|||||||
if product_name == gpu_upper:
|
if product_name == gpu_upper:
|
||||||
real_gpu_name = product.get("gpu", "Inconnu")
|
real_gpu_name = product.get("gpu", "Inconnu")
|
||||||
product_link = "https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&gpu=RTX%205090,RTX%205080"
|
product_link = "https://marketplace.nvidia.com/fr-fr/consumer/graphics-cards/?locale=fr-fr&page=1&limit=12&gpu=RTX%205090,RTX%205080"
|
||||||
msg = (
|
send_discord_notification(real_gpu_name, product_link)
|
||||||
f"@everyone **En stock !**\n"
|
|
||||||
f"Carte : **{real_gpu_name}**\n "
|
|
||||||
f"Lien :point_right: {product_link}\n"
|
|
||||||
f"________\n"
|
|
||||||
)
|
|
||||||
send_discord_notification(msg)
|
|
||||||
|
|
||||||
stock_status[gpu_upper] = True
|
stock_status[gpu_upper] = True
|
||||||
print(f"{gpu} est maintenant en stock!")
|
print(f"{gpu} est maintenant en stock!")
|
||||||
@ -126,11 +127,10 @@ def check_rtx_50_founders():
|
|||||||
logging.info(f"{gpu} n'est plus en stock.")
|
logging.info(f"{gpu} n'est plus en stock.")
|
||||||
stock_status[gpu_upper] = False
|
stock_status[gpu_upper] = False
|
||||||
print(f"{gpu} est hors stock !")
|
print(f"{gpu} est hors stock !")
|
||||||
|
|
||||||
elif not currently_in_stock:
|
elif not currently_in_stock:
|
||||||
print(f"{gpu} est actuellement hors stock.")
|
print(f"{gpu} est actuellement hors stock.")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
while True:
|
while True:
|
||||||
check_rtx_50_founders()
|
check_rtx_50_founders()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user