Fixed cache issues
This commit is contained in:
@@ -89,7 +89,11 @@ HEADERS = {
|
|||||||
"Sec-Fetch-Dest": "empty",
|
"Sec-Fetch-Dest": "empty",
|
||||||
"Sec-Fetch-Mode": "cors",
|
"Sec-Fetch-Mode": "cors",
|
||||||
"Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not.A/Brand\";v=\"24\"",
|
"Sec-Ch-Ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not.A/Brand\";v=\"24\"",
|
||||||
"Sec-Ch-Ua-Platform": "\"macOS\""
|
"Sec-Ch-Ua-Platform": "\"macOS\"",
|
||||||
|
# Headers anti-cache pour forcer la récupération de données fraîches
|
||||||
|
"Cache-Control": "no-cache, no-store, must-revalidate",
|
||||||
|
"Pragma": "no-cache",
|
||||||
|
"Expires": "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Load country setting and localization config
|
# Load country setting and localization config
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import requests
|
import requests
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
from env_config import HEADERS, PRODUCT_NAMES, API_URL_SKU, API_URL_STOCK, PRODUCT_URL
|
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 notifier import send_discord_notification, send_out_of_stock_notification, send_sku_change_notification
|
||||||
from requests.adapters import HTTPAdapter, Retry
|
from requests.adapters import HTTPAdapter, Retry
|
||||||
|
|
||||||
# HTTP session
|
# HTTP session avec configuration anti-cache
|
||||||
session = requests.Session()
|
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))
|
||||||
|
|
||||||
|
# Configuration de la session pour éviter le cache
|
||||||
|
session.headers.update(HEADERS)
|
||||||
|
|
||||||
# Keeping memory of last run
|
# Keeping memory of last run
|
||||||
last_sku_dict = {}
|
last_sku_dict = {}
|
||||||
global_stock_status_dict = {}
|
global_stock_status_dict = {}
|
||||||
@@ -18,9 +22,13 @@ first_run_dict = {name: True for name in PRODUCT_NAMES}
|
|||||||
def check_rtx_50_founders():
|
def check_rtx_50_founders():
|
||||||
global last_sku_dict, global_stock_status_dict, first_run_dict
|
global last_sku_dict, global_stock_status_dict, first_run_dict
|
||||||
|
|
||||||
# Fetching nvidia API data
|
# Fetching nvidia API data avec timestamp anti-cache
|
||||||
try:
|
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}")
|
logging.info(f"SKU API response: {response.status_code}")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@@ -56,12 +64,13 @@ def check_rtx_50_founders():
|
|||||||
last_sku_dict[product_name] = product_sku
|
last_sku_dict[product_name] = product_sku
|
||||||
first_run_dict[product_name] = False
|
first_run_dict[product_name] = False
|
||||||
|
|
||||||
# Check product availability in API_URL_STOCK for each SKU
|
# Check product availability in API_URL_STOCK for each SKU avec cache buster
|
||||||
api_stock_url = API_URL_STOCK + product_sku
|
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}")
|
logging.info(f"[{product_name}] Checking stock: {api_stock_url}")
|
||||||
|
|
||||||
try:
|
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}")
|
logging.info(f"[{product_name}] Stock API response: {response.status_code}")
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
stock_data = response.json()
|
stock_data = response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user