Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] KeyError: 'profile_def' on search #29

Closed
spurll opened this issue Sep 6, 2024 · 6 comments
Closed

[BUG] KeyError: 'profile_def' on search #29

spurll opened this issue Sep 6, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@spurll
Copy link

spurll commented Sep 6, 2024

Describe the bug
When searching by name or by ID, KeyError: 'profile_dev' occurs

To Reproduce

Python 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from howlongtobeatpy import HowLongToBeat
>>> HowLongToBeat()
<howlongtobeatpy.HowLongToBeat.HowLongToBeat object at 0x7b827079a5d0>
>>> HowLongToBeat().search("Ogre Battle")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/goodplays/venv/lib/python3.12/site-packages/howlongtobeatpy/HowLongToBeat.py", line 65, in search
    return self.__parse_web_result(game_name, html_result, None, similarity_case_sensitive)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/goodplays/venv/lib/python3.12/site-packages/howlongtobeatpy/HowLongToBeat.py", line 134, in __parse_web_result
    parser.parse_json_result(html_result)
  File "/opt/goodplays/venv/lib/python3.12/site-packages/howlongtobeatpy/JSONResultParser.py", line 40, in parse_json_result
    new_game_entry = self.parse_json_element(game)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/goodplays/venv/lib/python3.12/site-packages/howlongtobeatpy/JSONResultParser.py", line 61, in parse_json_element
    current_entry.profile_dev = input_game_element["profile_dev"]
                                ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'profile_dev'

HLTB API Version
v1.0.7

@tlt21
Copy link

tlt21 commented Sep 7, 2024

Looks like "profile_platform" is also missing. Had to comment out both to get search to work.
image

@ScrappyCocco ScrappyCocco added the bug Something isn't working label Sep 7, 2024
@ScrappyCocco
Copy link
Owner

It looks like the JSON no longer has those values
Example json:

{
   "game_id":42818,
   "game_name":"Celeste",
   "game_name_date":0,
   "game_alias":"",
   "game_type":"game",
   "game_image":"42818_Celeste.jpg",
   "comp_lvl_combine":0,
   "comp_lvl_sp":1,
   "comp_lvl_co":0,
   "comp_lvl_mp":0,
   "comp_main":29770,
   "comp_plus":51483,
   "comp_100":135404,
   "comp_all":44161,
   "comp_main_count":3039,
   "comp_plus_count":1679,
   "comp_100_count":657,
   "comp_all_count":5375,
   "invested_co":0,
   "invested_mp":0,
   "invested_co_count":0,
   "invested_mp_count":0,
   "count_comp":10830,
   "count_speedrun":98,
   "count_backlog":8912,
   "count_review":3795,
   "review_score":88,
   "count_playing":335,
   "count_retired":615,
   "profile_popular":1263,
   "release_world":2018
}

Should I put them to None if not present?

@ScrappyCocco
Copy link
Owner

ScrappyCocco commented Sep 7, 2024

I was thinking about doing

if "profile_dev" in input_game_element:
    current_entry.profile_dev = input_game_element["profile_dev"]
if "profile_platform" in input_game_element:
    current_entry.profile_platforms = input_game_element["profile_platform"].split(", ")
if "release_world" in input_game_element:
    current_entry.release_world = input_game_element["release_world"]

So if they ever appear again they're gonna be back there, otherwise they are None
Is it ok?

@spurll
Copy link
Author

spurll commented Sep 7, 2024

Seems reasonable to me, though wouldn't it be a bit more Pythonic to just get them, skipping the if?

current_entry.profile_dev = input_game_element.get("profile_dev")

I might be wrong, I've been pretty much out of the software game for a few years.

@ScrappyCocco
Copy link
Owner

Yes you're right, I'll do it this way, sorry I don't use Python very much

ScrappyCocco added a commit that referenced this issue Sep 7, 2024
@ScrappyCocco
Copy link
Owner

Fixed on version 1.0.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants