Skip to content

Commit 2490768

Browse files
committed
Faster regex
1 parent efa037c commit 2490768

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

howlongtobeatpy/howlongtobeatpy/HTMLRequests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __extract_search_url_script(self, script_content: str):
5050
# 2. Ensures the request options contain 'method: "POST"' to filter out the GET init call.
5151
pattern = re.compile(
5252
# Capture Group 1: The path suffix after /api/ (e.g., "search" or "find/v2")
53-
r'fetch\s*\(\s*["\']\/api\/([a-zA-Z0-9_/]+)[^"\']*["\']\s*,\s*{.*?\s*method:\s*["\']POST["\'].*?}',
53+
r'fetch\s*\(\s*["\']/api/([a-zA-Z0-9_/]+)[^"\']*["\']\s*,\s*{[^}]*method:\s*["\']POST["\'][^}]*}',
5454
re.DOTALL | re.IGNORECASE
5555
)
5656

@@ -185,7 +185,7 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
185185
if search_info_data is None or search_info_data.search_url is None:
186186
search_info_data = HTMLRequests.send_website_request_getcode(True)
187187
# Make the request
188-
if search_info_data.search_url is not None:
188+
if search_info_data is not None and search_info_data.search_url is not None:
189189
HTMLRequests.SEARCH_URL = HTMLRequests.BASE_URL + search_info_data.search_url
190190
payload = HTMLRequests.get_search_request_data(game_name, search_modifiers, page)
191191
resp = requests.post(HTMLRequests.SEARCH_URL, headers=headers, data=payload, timeout=60)
@@ -209,7 +209,7 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
209209
if search_info_data is None or search_info_data.search_url is None:
210210
search_info_data = HTMLRequests.send_website_request_getcode(True)
211211
# Make the request
212-
if search_info_data.search_url is not None:
212+
if search_info_data is not None and search_info_data.search_url is not None:
213213
HTMLRequests.SEARCH_URL = HTMLRequests.BASE_URL + search_info_data.search_url
214214
payload = HTMLRequests.get_search_request_data(game_name, search_modifiers, page)
215215
timeout = aiohttp.ClientTimeout(total=60)

0 commit comments

Comments
 (0)