import argparse
import logging

from unwind import db
from unwind.imdb import refresh_user_ratings_from_imdb

log = logging.getLogger(__name__)

name = "load-user-ratings-from-imdb"
help = """Load user ratings from imdb.com.
Refresh user ratings for all registered users live from IMDb's website.
"""


def add_args(cmd: argparse.ArgumentParser) -> None:
    pass


async def main(args: argparse.Namespace) -> None:
    await db.open_connection_pool()

    i = 0
    async for _ in refresh_user_ratings_from_imdb():
        i += 1

    log.info("✨ Imported %s new ratings.", i)

    await db.close_connection_pool()
