Skip to content

Commit 8684bd1

Browse files
committed
closes #8 - version 0.1.18
This version add the game title suffix For more informations see #8
1 parent ef2dcbc commit 8684bd1

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

howlongtobeatpy/howlongtobeatpy/HTMLResultParser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, input_game_name: str, input_game_url: str,
2929
self.current_entry = None
3030
self.li_encountered = False
3131
self.inside_a_div = False
32+
self.inside_a_strong = False
3233
self.inside_a_title_link = False
3334
self.currently_reading = None
3435
self.game_name = None
@@ -51,6 +52,8 @@ def handle_starttag(self, tag, attrs):
5152
self.current_entry = HowLongToBeatEntry()
5253

5354
if self.li_encountered: # If i already read the <li> tag i'm inside a game entry
55+
if tag == "strong":
56+
self.inside_a_strong = True
5457
if tag == "a": # The <a> tag contain the game title and the game page id
5558
for att in attrs:
5659
if att[0] == "title": # Read the current game title
@@ -72,6 +75,8 @@ def handle_starttag(self, tag, attrs):
7275
def handle_endtag(self, tag):
7376
if tag == "a" and self.inside_a_title_link: # No longer in the <a> link with the game name
7477
self.inside_a_title_link = False
78+
if tag == "strong" and self.inside_a_strong:
79+
self.inside_a_strong = False
7580
if tag == "div": # I save that i'm no longer inside a <div> element
7681
self.inside_a_div = False
7782
if tag == "li" and self.li_encountered: # I finished reading the game entry
@@ -97,7 +102,9 @@ def handle_endtag(self, tag):
97102
# OVERRIDE from HTMLParser
98103
def handle_data(self, data):
99104
if self.inside_a_title_link and len(data.strip()) > 0:
100-
self.current_entry.game_name = data.strip()
105+
self.current_entry.game_name = data.strip() # Save the title of the game
106+
if self.inside_a_strong and len(data.strip()) > 0:
107+
self.current_entry.game_name_suffix = data.strip() # Save the suffix of the game
101108
if self.inside_a_div:
102109
# If i'm inside a <div> i must analyze all the possible times, saving title and then his value
103110
if data.lower().strip() == "main story" \

howlongtobeatpy/howlongtobeatpy/HowLongToBeatEntry.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def __init__(self):
1111
# Base Game Details
1212
self.game_id = -1
1313
self.game_name = None
14+
self.game_name_suffix = None
1415
self.game_image_url = None
1516
self.game_web_link = None
1617
# Gameplay Main

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.17',
7+
version='0.1.18',
88
packages=find_packages(exclude=['tests']),
99
description='A Python API for How Long to Beat',
1010
long_description=long_description,

howlongtobeatpy/tests/test_async_request.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,24 @@ async def test_game_case_sensitive(self):
108108
self.assertTrue(best_element_standard.similarity <= best_element_not_case.similarity,
109109
"Wrong similarity results")
110110

111+
@async_test
112+
async def test_game_suffix_present(self):
113+
results = await HowLongToBeat(0).async_search("God Of War")
114+
self.assertNotEqual(None, results, "Search Results are None")
115+
self.assertNotEqual(0, len(results))
116+
best_element = max(results, key=lambda element: element.similarity)
117+
self.assertEqual("God of War".lower(), best_element.game_name.lower())
118+
self.assertNotEqual(None, best_element.game_name_suffix, "The suffix is still None, it should not be")
119+
self.assertEqual(best_element.game_name_suffix, "(2018)")
120+
121+
@async_test
122+
async def test_game_suffix_not_present(self):
123+
results = await HowLongToBeat(0).async_search("The Witcher 3: Wild Hunt")
124+
self.assertNotEqual(None, results, "Search Results are None")
125+
self.assertNotEqual(0, len(results))
126+
best_element = max(results, key=lambda element: element.similarity)
127+
self.assertEqual(None, best_element.game_name_suffix, "The suffix is not None, it should be")
128+
111129
@async_test
112130
async def test_no_real_game(self):
113131
results = await HowLongToBeat().async_search("asfjklagls")

howlongtobeatpy/tests/test_normal_request.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,22 @@ def test_game_case_sensitive(self):
119119
self.assertTrue(best_element_standard.similarity <= best_element_not_case.similarity,
120120
"Wrong similarity results")
121121

122+
def test_game_suffix_present(self):
123+
results = HowLongToBeat(0).search("God Of War")
124+
self.assertNotEqual(None, results, "Search Results are None")
125+
self.assertNotEqual(0, len(results))
126+
best_element = max(results, key=lambda element: element.similarity)
127+
self.assertEqual("God of War".lower(), best_element.game_name.lower())
128+
self.assertNotEqual(None, best_element.game_name_suffix, "The suffix is still None, it should not be")
129+
self.assertEqual(best_element.game_name_suffix, "(2018)")
130+
131+
def test_game_suffix_not_present(self):
132+
results = HowLongToBeat(0).search("The Witcher 3: Wild Hunt")
133+
self.assertNotEqual(None, results, "Search Results are None")
134+
self.assertNotEqual(0, len(results))
135+
best_element = max(results, key=lambda element: element.similarity)
136+
self.assertEqual(None, best_element.game_name_suffix, "The suffix is not None, it should be")
137+
122138
def test_no_real_game(self):
123139
results = HowLongToBeat().search("asfjklagls")
124140
self.assertEqual(0, len(results))

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.17
5+
sonar.projectVersion=0.1.18
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)