def get_movies_by_id(id_list, repo: AbstractRepository): movies = repo.get_movies_by_id(id_list) # Convert Movies to dictionary form. movies_as_dict = movies_to_dict(movies, id_list, repo) return movies_as_dict
def get_movies(movie_count: int, repo: AbstractRepository): id_list = [] for i in range(1, movie_count): id_list.append(i) # Get movies. movies = repo.get_movies_by_id(id_list) return movies_to_dict(movies)
def get_random_movies(quantity, repo: AbstractRepository): movie_count = repo.get_number_of_movies() if quantity >= movie_count: # Reduce the quantity of ids to generate if the repository has an insufficient number of articles. quantity = movie_count - 1 # Pick distinct and random articles. random_ids = random.sample(range(1, movie_count), quantity) movies = repo.get_movies_by_id(random_ids) return movies_to_dict(movies)