Spaces:
mxrkai
/
Runtime error

File size: 1,499 Bytes
0e86a5a
 
 
 
7737401
0ea73f2
 
 
0e86a5a
8d9643a
0e86a5a
7737401
e43189b
0e86a5a
 
 
 
 
 
 
 
7737401
0e86a5a
e43189b
0e86a5a
7737401
0e86a5a
 
 
7737401
0e86a5a
 
 
 
 
8d9643a
0e86a5a
 
0ea73f2
0e86a5a
 
0ea73f2
0e86a5a
 
0ea73f2
0e86a5a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import re
import time

from api.config import BASE_URL, headers
from api.logger import setup_logger

logger = setup_logger(__name__)

def getHid():
    try:
        # Fetch initial HTML content
        response = requests.get(BASE_URL, headers=headers)
        response.raise_for_status()
        content = response.text

        # Use regex to find the specific static/chunks path
        pattern = r"static/chunks/app/layout-[a-zA-Z0-9]+\.js"
        match = re.search(pattern, content)

        if match:
            # Construct the full URL of the JS file
            js_path = match.group()
            full_url = f"{BASE_URL}/_next/{js_path}"

            # Request JS file content
            js_response = requests.get(full_url, headers=headers)
            js_response.raise_for_status()

            # Search for h-value in the JS content using regex
            h_pattern = r'h="([0-9a-f-]+)"'
            h_match = re.search(h_pattern, js_response.text)

            if h_match:
                h_value = h_match.group(1)
                logger.info(f"Generated new h-value: {h_value}")
                return h_value
            else:
                logger.error("h-value not found in JS content")
                return None
        else:
            logger.error("JS file path not found in HTML content")
            return None
    except requests.exceptions.RequestException as e:
        logger.error(f"Error occurred while fetching hid: {e}")
        return None