hudsonbrendon / ha_epic_games

A custom component for home assistant
MIT License
9 stars 5 forks source link

Metacritic Entry Not Found #2

Closed SpiGAndromeda closed 9 months ago

SpiGAndromeda commented 10 months ago

Hi,

depending on the games, it might happen that no metacritic entry is available or that they simply cannot be found. If that happens the sensor cant be updated or setup at all if this happens after adding the integration.

I suggest to implement a fallback if the metacritic cannot be found. Unfortunatly, I rarely coded in Python at all. But I think it would be sufficient to wrap these lines with a try-catch (like the one for failed parsing).

search_url = f"https://www.metacritic.com/search/game/{game_name}/results?plats[3]=1&search_type=advanced"
response = requests.get(search_url, headers=self.headers)
response.raise_for_status()

The URL that currently cannot be found: https://www.metacritic.com/search/game/Tandem:%20A%20Tale%20of%20Shadows/results/?plats%5B3%5D=1&search_type=advanced

best regards, SpiGAndromeda

meyerdominik commented 10 months ago

Can confirm. Same for me:

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:573
Integration: Sensor (documentation, issues)
First occurred: 15:48:13 (1 occurrences)
Last logged: 15:48:13

epic_games: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 573, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 993, in async_device_update
    await hass.async_add_executor_job(self.update)
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/epic_games/sensor.py", line 176, in update
    [
  File "/config/custom_components/epic_games/sensor.py", line 182, in <listcomp>
    rating=self.get_score_metacritic(game.get("title")),
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/epic_games/sensor.py", line 139, in get_score_metacritic
    response.raise_for_status()
  File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://www.metacritic.com/search/game/Turnip%20Boy%20Commits%20Tax%20Evasion/results/?plats%5B3%5D=1&search_type=advanced
MrSteffenME commented 9 months ago

Hi,

The issue is still with us: File "/config/custom_components/epic_games/sensor.py", line 139, in get_score_metacritic response.raise_for_status() File "/usr/local/lib/python3.11/site-packages/requests/models.py", line 1021, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url

URL pointing to: https://www.metacritic.com/search/game/Surviving%20the%20Aftermath/results/?plats%5B3%5D=1&search_type=advanced

URL if i search the game: https://www.metacritic.com/game/surviving-the-aftermath/