Update api/validate.py
Browse files- api/validate.py +18 -2
api/validate.py
CHANGED
|
@@ -7,7 +7,20 @@ from api.logger import setup_logger
|
|
| 7 |
|
| 8 |
logger = setup_logger(__name__)
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
try:
|
| 12 |
# Fetch initial HTML content
|
| 13 |
response = requests.get(BASE_URL, headers=headers)
|
|
@@ -33,7 +46,10 @@ def getHid():
|
|
| 33 |
|
| 34 |
if h_match:
|
| 35 |
h_value = h_match.group(1)
|
| 36 |
-
logger.info(f"
|
|
|
|
|
|
|
|
|
|
| 37 |
return h_value
|
| 38 |
else:
|
| 39 |
logger.error("h-value not found in JS content")
|
|
|
|
| 7 |
|
| 8 |
logger = setup_logger(__name__)
|
| 9 |
|
| 10 |
+
# Cache variables
|
| 11 |
+
cached_hid = None
|
| 12 |
+
cache_time = 0
|
| 13 |
+
CACHE_DURATION = 36000 # Cache duration in seconds (10 hours)
|
| 14 |
+
|
| 15 |
+
def getHid(force_refresh=False):
|
| 16 |
+
global cached_hid, cache_time
|
| 17 |
+
current_time = time.time()
|
| 18 |
+
|
| 19 |
+
# Check if cache is valid and not forced to refresh
|
| 20 |
+
if not force_refresh and cached_hid and (current_time - cache_time) < CACHE_DURATION:
|
| 21 |
+
logger.info(f"Using cached_hid: {cached_hid}")
|
| 22 |
+
return cached_hid
|
| 23 |
+
|
| 24 |
try:
|
| 25 |
# Fetch initial HTML content
|
| 26 |
response = requests.get(BASE_URL, headers=headers)
|
|
|
|
| 46 |
|
| 47 |
if h_match:
|
| 48 |
h_value = h_match.group(1)
|
| 49 |
+
logger.info(f"Found new h-value: {h_value}")
|
| 50 |
+
# Update cache
|
| 51 |
+
cached_hid = h_value
|
| 52 |
+
cache_time = current_time
|
| 53 |
return h_value
|
| 54 |
else:
|
| 55 |
logger.error("h-value not found in JS content")
|