Fixed cache issues
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import requests
|
||||
import logging
|
||||
import time
|
||||
from env_config import HEADERS, PRODUCT_NAMES, API_URL_SKU, API_URL_STOCK, PRODUCT_URL
|
||||
from notifier import send_discord_notification, send_out_of_stock_notification, send_sku_change_notification
|
||||
from requests.adapters import HTTPAdapter, Retry
|
||||
|
||||
# HTTP session
|
||||
# HTTP session avec configuration anti-cache
|
||||
session = requests.Session()
|
||||
retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
|
||||
session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
|
||||
# Configuration de la session pour éviter le cache
|
||||
session.headers.update(HEADERS)
|
||||
|
||||
# Keeping memory of last run
|
||||
last_sku_dict = {}
|
||||
global_stock_status_dict = {}
|
||||
@@ -18,9 +22,13 @@ first_run_dict = {name: True for name in PRODUCT_NAMES}
|
||||
def check_rtx_50_founders():
|
||||
global last_sku_dict, global_stock_status_dict, first_run_dict
|
||||
|
||||
# Fetching nvidia API data
|
||||
# Fetching nvidia API data avec timestamp anti-cache
|
||||
try:
|
||||
response = session.get(API_URL_SKU, headers=HEADERS, timeout=10)
|
||||
# Ajout d'un paramètre timestamp pour éviter le cache
|
||||
cache_buster = int(time.time() * 1000) # timestamp en millisecondes
|
||||
sku_url = f"{API_URL_SKU}&_t={cache_buster}"
|
||||
|
||||
response = session.get(sku_url, timeout=10)
|
||||
logging.info(f"SKU API response: {response.status_code}")
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
@@ -56,12 +64,13 @@ def check_rtx_50_founders():
|
||||
last_sku_dict[product_name] = product_sku
|
||||
first_run_dict[product_name] = False
|
||||
|
||||
# Check product availability in API_URL_STOCK for each SKU
|
||||
api_stock_url = API_URL_STOCK + product_sku
|
||||
# Check product availability in API_URL_STOCK for each SKU avec cache buster
|
||||
cache_buster = int(time.time() * 1000) # timestamp en millisecondes
|
||||
api_stock_url = f"{API_URL_STOCK}{product_sku}&_t={cache_buster}"
|
||||
logging.info(f"[{product_name}] Checking stock: {api_stock_url}")
|
||||
|
||||
try:
|
||||
response = session.get(api_stock_url, headers=HEADERS, timeout=10)
|
||||
response = session.get(api_stock_url, timeout=10)
|
||||
logging.info(f"[{product_name}] Stock API response: {response.status_code}")
|
||||
response.raise_for_status()
|
||||
stock_data = response.json()
|
||||
|
||||
Reference in New Issue
Block a user