Skip to content

Commit

Permalink
Do not fail on error date #5
Browse files Browse the repository at this point in the history
  • Loading branch information
solesensei committed Sep 3, 2022
1 parent dc7a22f commit 26df6a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ngl/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ def _add_row(self, collection: Collection, **row_data) -> CollectionRowBlock:
def _parse_date(date_str: tp.Optional[str]):
if not date_str:
return None
check_date_formats = (r"%d %b, %Y", r"%b %d, %Y", r"%b %Y")
check_date_formats = (r"%d %b, %Y", r"%b %d, %Y", r"%b %Y", r"%d %b %Y", r"%b %d %Y", r"%Y")
for fmt in check_date_formats:
try:
return datetime.strptime(date_str, fmt).date()
except ValueError:
pass
raise ServiceError(msg="time data '{}' does not match any of formats '{}'".format(date_str, "', '".join(check_date_formats)))
echo.r("\nDate: '{}' does not match any of formats '{}' | skip".format(date_str, "', '".join(check_date_formats)))
return None

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}"}
Expand All @@ -114,7 +115,7 @@ def add_game(self, game: GameInfo, game_page: CollectionViewPageBlock, use_bg_as

def import_game_list(self, game_list: tp.List[GameInfo], game_page: CollectionViewPageBlock, **kwargs) -> tp.List[GameInfo]:
errors = []
for i, game in enumerate(game_list):
for i, game in enumerate(game_list, start=1):
echo.c(f"Imported: {i}/{len(game_list)}", end="\r")
if not self.add_game(game, game_page, **kwargs):
errors.append(game)
Expand Down

0 comments on commit 26df6a0

Please sign in to comment.