Skip to content

Commit 02639a1

Browse files
committed
A small code cleanup for the next version
1 parent 8ce01f8 commit 02639a1

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

howlongtobeatpy/howlongtobeatpy/HTMLRequests.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ class SearchModifiers(Enum):
1616
NONE = ""
1717
# ISOLATE_DLC shows only DLC in the search result
1818
ISOLATE_DLC = "only_dlc"
19-
# HIDE_DLC hide DLCs in the search result
19+
# ISOLATE_MODS shows only MODs
20+
ISOLATE_MODS = "only_mods"
21+
# ISOLATE_HACKS shows only Hacks
22+
ISOLATE_HACKS = "only_hacks"
23+
# HIDE_DLC hide DLCs/MODs in the search result
2024
HIDE_DLC = "hide_dlc"
2125

2226

@@ -151,15 +155,6 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
151155
return await resp_user_id.text()
152156
return None
153157

154-
payload = HTMLRequests.get_search_request_data(game_name, search_modifiers, page, api_key_result)
155-
# Make the post request and return the result if is valid
156-
search_url_with_key = HTMLRequests.SEARCH_URL + "/" + api_key_result
157-
async with aiohttp.ClientSession() as session:
158-
async with session.post(search_url_with_key, headers=headers, data=payload) as resp:
159-
if resp is not None and str(resp.status) == "200":
160-
return await resp.text()
161-
return None
162-
163158
@staticmethod
164159
def __cut_game_title(page_source: str):
165160
"""
@@ -235,7 +230,7 @@ async def async_get_game_title(game_id: int):
235230
# Request and extract title
236231
async with aiohttp.ClientSession() as session:
237232
async with session.post(HTMLRequests.GAME_URL, params=params, headers=headers) as resp:
238-
if resp is not None and str(resp.status) == "200":
233+
if resp is not None and resp.status == 200:
239234
text = await resp.text()
240235
return HTMLRequests.__cut_game_title(text)
241236
return None

howlongtobeatpy/howlongtobeatpy/HowLongToBeat.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
class HowLongToBeat:
1313
"""
1414
Main class that contain the base "search" function
15-
The search function is available using standard request or using an async request that MUST be awaited
15+
The search function is available using standard request
16+
Or using an async request, remember that request MUST be awaited
1617
"""
1718

1819
# ------------------------------------------
@@ -73,7 +74,7 @@ async def async_search_from_id(self, game_id: int):
7374
"""
7475
Function that search the game using an async request
7576
To re-use code, I extract the game name and search game by name, picking only the game with the same id
76-
Remember that this function use 2 requests: one to get the game title and one to get game data
77+
Remember that this function use one extra request: one to get the game title and one to get game data
7778
@param game_id: The game id to get data
7879
@return: The game data (single HowLongToBeatEntry object) or None in case of error
7980
"""
@@ -84,7 +85,7 @@ async def async_search_from_id(self, game_id: int):
8485
html_result = await HTMLRequests.send_async_web_request(game_title)
8586
if html_result is not None:
8687
result_list = self.__parse_web_result(game_title, html_result, game_id)
87-
if result_list is None or len(result_list) == 0 or len(result_list) > 1:
88+
if result_list is None or len(result_list) != 1:
8889
return None
8990
return result_list[0]
9091
return None
@@ -93,7 +94,7 @@ async def async_search_from_id(self, game_id: int):
9394
def search_from_id(self, game_id: int):
9495
"""
9596
To re-use code, I extract the game name and search game by name, picking only the game with the same id
96-
Remember that this function use 2 requests: one to get the game title and one to get game data
97+
Remember that this function use use one extra request: one to get the game title and one to get game data
9798
@param game_id: The game id to get data
9899
@return: The game data (single HowLongToBeatEntry object) None in case of error
99100
"""
@@ -104,7 +105,7 @@ def search_from_id(self, game_id: int):
104105
html_result = HTMLRequests.send_web_request(game_title)
105106
if html_result is not None:
106107
result_list = self.__parse_web_result(game_title, html_result, game_id)
107-
if result_list is None or len(result_list) == 0 or len(result_list) > 1:
108+
if result_list is None or len(result_list) != 1:
108109
return None
109110
return result_list[0]
110111
return None

0 commit comments

Comments
 (0)