diff --git a/unwind/imdb_import.py b/unwind/imdb_import.py index 3cd139a..57d21a3 100644 --- a/unwind/imdb_import.py +++ b/unwind/imdb_import.py @@ -189,40 +189,38 @@ async def import_from_file(*, basics_path: Path, ratings_path: Path): perc = 0.0 perc_step = 0.001 - async with db.shared_connection().transaction(): + chunk = [] - chunk = [] + for i, m in enumerate(read_basics(basics_path)): - for i, m in enumerate(read_basics(basics_path)): + if i / total > perc: + log.info("⏳ Imported %s%%", round(perc * 100, 1)) + perc += perc_step - if i / total > perc: - log.info("⏳ Imported %s%%", round(perc * 100, 1)) - perc += perc_step + if m.media_type not in { + "Movie", + "Short", + "TV Mini Series", + "TV Movie", + "TV Series", + "TV Short", + "TV Special", + "Video", + }: + log.debug("Skipping movie, unwanted media type: %s", m.media_type) + continue - if m.media_type not in { - "Movie", - "Short", - "TV Mini Series", - "TV Movie", - "TV Series", - "TV Short", - "TV Special", - "Video", - }: - log.debug("Skipping movie, unwanted media type: %s", m.media_type) - continue + m.score = scores.get(m.imdb_id) + chunk.append(m) - m.score = scores.get(m.imdb_id) - chunk.append(m) - - if len(chunk) > 1000: - await add_or_update_many_movies(chunk) - chunk = [] - - if chunk: + if len(chunk) > 1000: await add_or_update_many_movies(chunk) chunk = [] + if chunk: + await add_or_update_many_movies(chunk) + chunk = [] + async def load_from_web(): """Refresh the full IMDb movie database.