try1
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import requests
|
||||
import logging
|
||||
import time
|
||||
import random
|
||||
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 with stealth configuration
|
||||
session = requests.Session()
|
||||
retries = Retry(total=5, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
|
||||
session.mount('https://', HTTPAdapter(max_retries=retries))
|
||||
retries = Retry(total=2, backoff_factor=3, status_forcelist=[500, 502, 503, 504, 429])
|
||||
adapter = HTTPAdapter(max_retries=retries, pool_connections=1, pool_maxsize=1)
|
||||
session.mount('https://', adapter)
|
||||
session.headers.update(HEADERS)
|
||||
|
||||
# Keeping memory of last run
|
||||
@@ -20,13 +22,24 @@ 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
|
||||
|
||||
# Random delay to avoid pattern detection
|
||||
time.sleep(random.uniform(2, 6))
|
||||
|
||||
# Fetching nvidia API data
|
||||
try:
|
||||
cache_buster = int(time.time() * 1000)
|
||||
sku_url = f"{API_URL_SKU}&_t={cache_buster}"
|
||||
# Vary cache buster format to avoid pattern
|
||||
if random.choice([True, False]):
|
||||
cache_buster = f"v{random.randint(100, 999)}"
|
||||
else:
|
||||
cache_buster = f"{int(time.time() % 100000)}"
|
||||
sku_url = f"{API_URL_SKU}&cb={cache_buster}"
|
||||
|
||||
response = session.get(sku_url, timeout=10)
|
||||
response = session.get(sku_url, timeout=20)
|
||||
logging.info(f"SKU API response: {response.status_code}")
|
||||
if response.status_code == 429:
|
||||
logging.warning("Rate limited, waiting longer...")
|
||||
time.sleep(random.uniform(10, 20))
|
||||
return
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
@@ -61,14 +74,23 @@ def check_rtx_50_founders():
|
||||
last_sku_dict[product_name] = product_sku
|
||||
first_run_dict[product_name] = False
|
||||
|
||||
# Random delay between requests
|
||||
time.sleep(random.uniform(1, 4))
|
||||
|
||||
# Check product availability in API_URL_STOCK for each SKU
|
||||
cache_buster = int(time.time() * 1000)
|
||||
api_stock_url = f"{API_URL_STOCK}{product_sku}&_t={cache_buster}"
|
||||
if random.choice([True, False]):
|
||||
cache_param = f"v{random.randint(100, 999)}"
|
||||
else:
|
||||
cache_param = f"{int(time.time() % 100000)}"
|
||||
api_stock_url = f"{API_URL_STOCK}{product_sku}&cb={cache_param}"
|
||||
logging.info(f"[{product_name}] Checking stock: {api_stock_url}")
|
||||
|
||||
try:
|
||||
response = session.get(api_stock_url, timeout=10)
|
||||
response = session.get(api_stock_url, timeout=20)
|
||||
logging.info(f"[{product_name}] Stock API response: {response.status_code}")
|
||||
if response.status_code == 429:
|
||||
logging.warning(f"[{product_name}] Rate limited, skipping...")
|
||||
continue
|
||||
response.raise_for_status()
|
||||
stock_data = response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
|
||||
Reference in New Issue
Block a user