Skip to content

Commit

Permalink
6 crashes while fetching game data (#10)
Browse files Browse the repository at this point in the history
* Add checks before fetching game cover from `img_logo_url`

* Add checks on NULL for `playtime_forever` option

* up version

* Add check for conflicting arguments
  • Loading branch information
solesensei authored Oct 29, 2022
1 parent 0bda0bf commit a9a7a3d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Notion Game List ![](https://img.shields.io/badge/version-0.0.7-blue) ![](https://app.travis-ci.com/solesensei/notion-game-list.svg?branch=master) [![discuss](https://img.shields.io/reddit/subreddit-subscribers/notion?label=Discuss%20r%2Fnotion-games-list&style=social)](https://www.reddit.com/r/Notion/comments/jiy1sb/notion_games_list/?utm_source=share&utm_medium=web2x&context=3)
# Notion Game List ![](https://img.shields.io/badge/version-0.0.8-blue) ![](https://app.travis-ci.com/solesensei/notion-game-list.svg?branch=master) [![discuss](https://img.shields.io/reddit/subreddit-subscribers/notion?label=Discuss%20r%2Fnotion-games-list&style=social)](https://www.reddit.com/r/Notion/comments/jiy1sb/notion_games_list/?utm_source=share&utm_medium=web2x&context=3)


All your games inside [Notion](https://www.notion.so/solesensei/Notion-Game-List-generated-0d0d39993755415bb8812563a2781d84).
Expand Down
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
parser.add_argument("--steam-no-cache", help="Do not use cached fetched games", action="store_true")
args = parser.parse_args()

assert not (args.skip_non_steam and args.use_only_library), "You can't use --skip-non-steam and --use-only-library together"

STEAM_USER = args.steam_user or STEAM_USER

echo.y("Logging into Notion...")
Expand Down
11 changes: 7 additions & 4 deletions ngl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,16 @@ def _parse_date(date_str: tp.Optional[str]):
def add_game(self, game: GameInfo, game_page: CollectionViewPageBlock, use_bg_as_cover: bool = False) -> bool:
row_data = {"title": game.name, "platforms": game.platforms, "release_date": self._parse_date(game.release_date), "notes": f"Playtime: {game.playtime}"}
row = self._add_row(game_page.collection, **row_data)
row.icon = game.icon_uri
row.icon = game.icon_uri or self._gl_icon
with self.client.as_atomic_transaction():
# Game cover image
cover_img_uri = game.bg_uri or game.logo_uri if use_bg_as_cover else game.logo_uri
self.client.submit_transaction(
build_operation(row.id, path=["format", "page_cover"], command="set", args=cover_img_uri, table="block")
)
if cover_img_uri:
self.client.submit_transaction(
build_operation(row.id, path=["format", "page_cover"], command="set", args=cover_img_uri, table="block")
)
else:
echo.y(f"Game '{game.name}:{game.id}' does not have cover image")
return True

def import_game_list(self, game_list: tp.List[GameInfo], game_page: CollectionViewPageBlock, **kwargs) -> tp.List[GameInfo]:
Expand Down
32 changes: 20 additions & 12 deletions ngl/games/steam.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _get_bg_image(self, game_id: TGameID) -> tp.Optional[str]:
return None

@staticmethod
def _playtime_format(playtime_in_minutes):
def _playtime_format(playtime_in_minutes: int) -> str:
if playtime_in_minutes == 0:
return "never"
if playtime_in_minutes < 120:
Expand Down Expand Up @@ -129,28 +129,36 @@ def _fetch_library_games(self, skip_non_steam: bool = False, skip_free_games: bo
if game_id in self._games:
continue
echo.c(" " * 100 + f"\rFetching [{i}/{number_of_games}]: {g.name}", end="\r")
try:
steam_game = self.store.get_game_info(game_id) if not library_only else None
if steam_game is None and not library_only:
echo.m(f"Game {g.name} id:{game_id} not fetched from Steam store, skip it!")
self._store_skipped.append(game_id)
except SteamApiNotFoundError:
if skip_non_steam:
steam_game = None
if not library_only:
# Fetch game info from steam store
try:
steam_game = self.store.get_game_info(game_id)
except SteamApiNotFoundError:
pass

if steam_game is None and skip_non_steam:
echo.m(f"Game {g.name} id:{game_id} not found in Steam store, skip it")
self._store_skipped.append(game_id)
continue

echo.r(f"Game {g.name} id:{game_id} not found in Steam store, fetching details from library")
steam_game = None

logo_uri = steam_game.header_image if steam_game is not None and steam_game.header_image else self._image_link(game_id, g.img_logo_url)
logo_uri = None
if steam_game is not None and steam_game.header_image:
logo_uri = steam_game.header_image
elif getattr(g, "img_logo_url", None):
logo_uri = self._image_link(game_id, g.img_logo_url)

game_info = GameInfo(
id=game_id,
name=g.name,
platforms=[PLATFORM],
release_date=steam_game.release_date.date if steam_game is not None else None,
playtime=self._playtime_format(g.playtime_forever),
playtime=self._playtime_format(g.playtime_forever) if getattr(g, "playtime_forever", None) is not None else None,
logo_uri=logo_uri,
bg_uri=self._get_bg_image(game_id),
icon_uri=self._image_link(game_id, g.img_icon_url),
icon_uri=self._image_link(game_id, g.img_icon_url) if getattr(g, "img_icon_url", None) is not None else None,
free=steam_game.is_free if steam_game is not None else None,
)
if steam_game is not None:
Expand Down

0 comments on commit a9a7a3d

Please sign in to comment.