コード例 #1
0
def load_movies_and_ids(data_path: str, repo: MemoryRepository):
    ids = dict()
    for row in read_csv_file(os.path.join(data_path, 'moviefile.csv')):
        movie = Movie(row[1], int(row[6]))
        movie.id = int(row[0])
        movie.description = row[3]
        movie.runtime_minutes = int(row[7])

        director = Director(row[4])
        repo.add_director(director)
        movie.director = director

        parsed_genres = row[2].split(',')
        for genre_string in parsed_genres:
            genre = Genre(genre_string)
            movie.add_genre(genre)
            repo.add_genre(genre)

            parsed_actors = row[5].split(',')
            for actor_string in parsed_actors:
                actor = Actor(actor_string)
                repo.add_actor(actor)
                movie.add_actor(actor)

        # Add the Movie to the repository.
        repo.add_movie(movie)
        repo.add_movie_index(movie)
コード例 #2
0
 def add_movie(self, movie: Movie):
     movie.id = len(self._movies) + 1
     self._movies.append(movie)
     self._movies_title.append(movie)