Skip to content

Commit 053f91f

Browse files
committed
Small code rework - version 0.1.20
1 parent 1c87371 commit 053f91f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

howlongtobeatpy/howlongtobeatpy/HTMLRequests.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SearchModifiers(Enum):
2323

2424
class HTMLRequests:
2525
BASE_URL = 'https://howlongtobeat.com/'
26+
ORIGIN_HEADER = 'https://howlongtobeat.com'
27+
REFERER_HEADER = BASE_URL
2628
SEARCH_URL = BASE_URL + "search_results"
2729
GAME_URL = BASE_URL + "game?id="
2830

@@ -43,8 +45,8 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
4345
'content-type': 'application/x-www-form-urlencoded',
4446
'accept': '*/*',
4547
'User-Agent': ua.random,
46-
'origin': 'https://howlongtobeat.com',
47-
'referer': 'https://howlongtobeat.com/'
48+
'origin': HTMLRequests.ORIGIN_HEADER,
49+
'referer': HTMLRequests.REFERER_HEADER
4850
}
4951
payload = {
5052
'queryString': game_name,
@@ -63,7 +65,7 @@ def send_web_request(game_name: str, search_modifiers: SearchModifiers = SearchM
6365
}
6466
# Make the post request and return the result if is valid
6567
resp = requests.post(HTMLRequests.SEARCH_URL, params=params, headers=headers, data=payload)
66-
if resp is not None and resp.status_code == 200:
68+
if resp.status_code == 200:
6769
return resp.text
6870
else:
6971
return None
@@ -85,8 +87,8 @@ async def send_async_web_request(game_name: str, search_modifiers: SearchModifie
8587
'content-type': 'application/x-www-form-urlencoded',
8688
'accept': '*/*',
8789
'User-Agent': ua.random,
88-
'origin': 'https://howlongtobeat.com',
89-
'referer': 'https://howlongtobeat.com/'
90+
'origin': HTMLRequests.ORIGIN_HEADER,
91+
'referer': HTMLRequests.REFERER_HEADER
9092
}
9193
payload = {
9294
'queryString': game_name,
@@ -124,7 +126,7 @@ def __cut_game_title(game_title: str):
124126
if game_title is None or len(game_title) == 0:
125127
return None
126128

127-
title = re.search("<title>([\w\W]*)<\/title>", game_title)
129+
title = re.search("<title>(.*)<\/title>", game_title)
128130
# The position of start and end of this method may change if the website change
129131
cut_title = str(html.unescape(title.group(1)[12:-17]))
130132
return cut_title
@@ -143,7 +145,7 @@ def get_game_title(game_id: int):
143145
}
144146
headers = {
145147
'User-Agent': ua.random,
146-
'referer': 'https://howlongtobeat.com/'
148+
'referer': HTMLRequests.REFERER_HEADER
147149
}
148150

149151
# Request and extract title
@@ -164,7 +166,7 @@ async def async_get_game_title(game_id: int):
164166
}
165167
headers = {
166168
'User-Agent': ua.random,
167-
'referer': 'https://howlongtobeat.com/'
169+
'referer': HTMLRequests.REFERER_HEADER
168170
}
169171

170172
# Request and extract title

howlongtobeatpy/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
long_description = fh.read()
55

66
setup(name='howlongtobeatpy',
7-
version='0.1.19',
7+
version='0.1.20',
88
packages=find_packages(exclude=['tests']),
99
description='A Python API for How Long to Beat',
1010
long_description=long_description,

sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ sonar.organization=scrappycocco-github
22
sonar.projectKey=ScrappyCocco_HowLongToBeat-PythonAPI
33

44
sonar.projectName=HowLongToBeat-PythonAPI
5-
sonar.projectVersion=0.1.19
5+
sonar.projectVersion=0.1.20
66

77
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
88
# This property is optional if sonar.modules is set.

0 commit comments

Comments
 (0)