Update api/validate.py
Browse files- api/validate.py +18 -17
api/validate.py
CHANGED
@@ -2,10 +2,11 @@ import requests
|
|
2 |
import re
|
3 |
import time
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
# Cache variables
|
11 |
cached_hid = None
|
@@ -16,18 +17,18 @@ def getHid(force_refresh=False):
|
|
16 |
global cached_hid, cache_time
|
17 |
current_time = time.time()
|
18 |
|
19 |
-
# Check if
|
20 |
if not force_refresh and cached_hid and (current_time - cache_time) < CACHE_DURATION:
|
21 |
-
|
22 |
return cached_hid
|
23 |
|
24 |
try:
|
25 |
-
#
|
26 |
-
response = requests.get(BASE_URL, headers=
|
27 |
response.raise_for_status()
|
28 |
content = response.text
|
29 |
|
30 |
-
#
|
31 |
pattern = r"static/chunks/app/layout-[a-zA-Z0-9]+\.js"
|
32 |
match = re.search(pattern, content)
|
33 |
|
@@ -36,27 +37,27 @@ def getHid(force_refresh=False):
|
|
36 |
js_path = match.group()
|
37 |
full_url = f"{BASE_URL}/_next/{js_path}"
|
38 |
|
39 |
-
# Request JS file content
|
40 |
-
js_response = requests.get(full_url, headers=
|
41 |
js_response.raise_for_status()
|
42 |
|
43 |
-
# Search for h-value in the JS content
|
44 |
h_pattern = r'h="([0-9a-f-]+)"'
|
45 |
h_match = re.search(h_pattern, js_response.text)
|
46 |
|
47 |
if h_match:
|
48 |
h_value = h_match.group(1)
|
49 |
-
|
50 |
-
# Update cache
|
51 |
cached_hid = h_value
|
52 |
cache_time = current_time
|
53 |
return h_value
|
54 |
else:
|
55 |
-
|
56 |
return None
|
57 |
else:
|
58 |
-
|
59 |
return None
|
60 |
except requests.exceptions.RequestException as e:
|
61 |
-
|
62 |
return None
|
|
|
2 |
import re
|
3 |
import time
|
4 |
|
5 |
+
BASE_URL = "https://www.blackbox.ai"
|
6 |
+
HEADERS = {
|
7 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
|
8 |
+
" Chrome/91.0.4472.124 Safari/537.36"
|
9 |
+
}
|
10 |
|
11 |
# Cache variables
|
12 |
cached_hid = None
|
|
|
17 |
global cached_hid, cache_time
|
18 |
current_time = time.time()
|
19 |
|
20 |
+
# Check if we should use the cached HID
|
21 |
if not force_refresh and cached_hid and (current_time - cache_time) < CACHE_DURATION:
|
22 |
+
print("Using cached HID:", cached_hid)
|
23 |
return cached_hid
|
24 |
|
25 |
try:
|
26 |
+
# Get initial HTML content
|
27 |
+
response = requests.get(BASE_URL, headers=HEADERS)
|
28 |
response.raise_for_status()
|
29 |
content = response.text
|
30 |
|
31 |
+
# Find the specific static/chunks path
|
32 |
pattern = r"static/chunks/app/layout-[a-zA-Z0-9]+\.js"
|
33 |
match = re.search(pattern, content)
|
34 |
|
|
|
37 |
js_path = match.group()
|
38 |
full_url = f"{BASE_URL}/_next/{js_path}"
|
39 |
|
40 |
+
# Request the JS file content
|
41 |
+
js_response = requests.get(full_url, headers=HEADERS)
|
42 |
js_response.raise_for_status()
|
43 |
|
44 |
+
# Search for the h-value in the JS content
|
45 |
h_pattern = r'h="([0-9a-f-]+)"'
|
46 |
h_match = re.search(h_pattern, js_response.text)
|
47 |
|
48 |
if h_match:
|
49 |
h_value = h_match.group(1)
|
50 |
+
print("Found h-value:", h_value)
|
51 |
+
# Update the cache
|
52 |
cached_hid = h_value
|
53 |
cache_time = current_time
|
54 |
return h_value
|
55 |
else:
|
56 |
+
print("h-value not found in JS content")
|
57 |
return None
|
58 |
else:
|
59 |
+
print("Specified JS file path not found in HTML content")
|
60 |
return None
|
61 |
except requests.exceptions.RequestException as e:
|
62 |
+
print(f"An error occurred: {e}")
|
63 |
return None
|