diff --git a/.vscode/settings.json b/.vscode/settings.json index e1f4b05..5951134 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,4 +4,4 @@ ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true -} \ No newline at end of file +} diff --git a/howlongtobeatpy/howlongtobeatpy/HTMLRequests.py b/howlongtobeatpy/howlongtobeatpy/HTMLRequests.py index f601932..db7094a 100644 --- a/howlongtobeatpy/howlongtobeatpy/HTMLRequests.py +++ b/howlongtobeatpy/howlongtobeatpy/HTMLRequests.py @@ -116,8 +116,9 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie headers = HTMLRequests.get_search_request_headers() payload = HTMLRequests.get_search_request_data(game_name, search_modifiers, page) # Make the post request and return the result if is valid + search_url_with_key = HTMLRequests.SEARCH_URL + "/" + HTMLRequests.SEARCH_API_KEY async with aiohttp.ClientSession() as session: - async with session.post(HTMLRequests.SEARCH_URL, headers=headers, data=payload) as resp: + async with session.post(search_url_with_key, headers=headers, data=payload) as resp: if resp is not None and str(resp.status) == "200": return await resp.text() return None @@ -226,3 +227,38 @@ def send_website_request_getcode(parse_all_scripts: bool): for match in matches: return match return None + + @staticmethod + async def async_send_website_request_getcode(parse_all_scripts: bool): + """ + Function that send a request to howlongtobeat to scrape the /api/search key + @return: The string key to use on /api/search + """ + # Make the post request and return the result if is valid + headers = HTMLRequests.get_title_request_headers() + async with aiohttp.ClientSession() as session: + async with session.get(HTMLRequests.BASE_URL, headers=headers) as resp: + if resp is not None and str(resp.status) == "200": + resp_text = await resp.text() + # Parse the HTML content using BeautifulSoup + soup = BeautifulSoup(resp_text, 'html.parser') + # Find all