Skip to content

Commit 229e742

Browse files
committed
Small changes for the future
1 parent 76df376 commit 229e742

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

howlongtobeatpy/howlongtobeatpy/HTMLRequests.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class HTMLRequests:
107107
GAME_URL = BASE_URL + "game"
108108
# Static search url to use in case it can't be extracted from JS code
109109
SEARCH_URL = BASE_URL + "api/s/"
110+
HTML_PARSER = 'html.parser'
110111

111112
@staticmethod
112113
def get_search_request_headers(auth_struct, user_agent):
@@ -266,7 +267,7 @@ def __cut_game_title(page_source: str):
266267
if page_source is None or len(page_source) == 0:
267268
return None
268269

269-
soup = BeautifulSoup(page_source, 'html.parser')
270+
soup = BeautifulSoup(page_source, HTMLRequests.HTML_PARSER)
270271
title_tag = soup.title
271272
title_text = title_tag.string
272273

@@ -352,7 +353,7 @@ def send_website_request_getcode(parse_all_scripts: bool, user_agent):
352353
resp = requests.get(HTMLRequests.BASE_URL, headers=headers, timeout=60)
353354
if resp.status_code == 200 and resp.text is not None:
354355
# Parse the HTML content using BeautifulSoup
355-
soup = BeautifulSoup(resp.text, 'html.parser')
356+
soup = BeautifulSoup(resp.text, HTMLRequests.HTML_PARSER)
356357
# Find all <script> tags with a src attribute containing the substring
357358
scripts = soup.find_all('script', src=True)
358359
if parse_all_scripts:
@@ -382,7 +383,7 @@ async def async_send_website_request_getcode(parse_all_scripts: bool, user_agent
382383
if resp is not None and resp.status == 200:
383384
resp_text = await resp.text()
384385
# Parse the HTML content using BeautifulSoup
385-
soup = BeautifulSoup(resp_text, 'html.parser')
386+
soup = BeautifulSoup(resp_text, HTMLRequests.HTML_PARSER)
386387
# Find all <script> tags with a src attribute containing the substring
387388
scripts = soup.find_all('script', src=True)
388389
if parse_all_scripts:

howlongtobeatpy/howlongtobeatpy/JSONResultParser.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
import json
55
import re
6-
from .HowLongToBeatEntry import HowLongToBeatEntry
6+
import math
77
from difflib import SequenceMatcher
8+
from .HowLongToBeatEntry import HowLongToBeatEntry
89

910
# ---------------------------------------------------------------------
1011

@@ -47,7 +48,7 @@ def parse_json_result(self, input_json_result):
4748
if self.game_id is not None and str(new_game_entry.game_id) != str(self.game_id):
4849
continue
4950
# Minimum Similarity is 0 so just add it straight away
50-
elif self.minimum_similarity == 0.0:
51+
elif math.isclose(self.minimum_similarity, 0.0, abs_tol=1e-9):
5152
self.results.append(new_game_entry)
5253
# Add it if it respects the minimum similarity
5354
elif new_game_entry.similarity >= self.minimum_similarity:

0 commit comments

Comments
 (0)