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)
def load_all(file_name: str, repo: MemoryRepository): with open(file_name, mode='r', encoding='utf-8-sig') as csvfile: movie_file_reader = csv.DictReader(csvfile) for row in movie_file_reader: movie = Movie(row['Title'], int(row['Year'])) movie.description = row['Description'] movie.runtime_minutes = int(row['Runtime (Minutes)']) director = Director(row['Director']) repo.add_director(director) movie.director = director parsed_genres = row['Genre'].split(',') for genre_string in parsed_genres: genre = Genre(genre_string) repo.add_genre(genre) movie.add_genre(genre) parsed_actors = row['Actors'].split(',') for actor_string in parsed_actors: actor = Actor(actor_string) repo.add_actor(actor) movie.add_actor(actor) repo.add_movie(movie)
def dict_to_movie(dict): movie = Movie(dict.title, dict.release_year, dict.id) movie.add_actor(dict.actors) for genre in dict.genre: movie.add_genre(genre) movie.director = dict.director movie.runtime_minutes = dict.runtime_minutes movie.description = dict.description return movie
def load_movies(): data_path = os.path.join("movie", "adapters", "data") # print(data_path, '#'*10) moive_list = [] director1 = Director("Joss Whedon") director2 = Director("Anthony Russo") actor1 = Actor("Robert Downey") actor2 = Actor("Chris Evans") genre1 = Genre("fiction") genre2 = Genre("action") for data_row in read_csv_file(os.path.join(data_path, "news_movies.csv")): # print(data_row, '#'*5) movie_key = int(data_row[0]) # Create Moive object. movie = Movie( title=data_row[1], # date=date.fromisoformat(data_row[2]), release_year=data_row[2], # image_hyperlink=data_row[5], id=movie_key, ) # add realted director if movie_key == 1: movie.director = director1 movie.add_actor(actor1) movie.add_actor(actor2) movie.add_genre(genre1) movie.add_genre(genre2) elif movie_key == 2: movie.director = director1 movie.add_actor(actor1) movie.add_actor(actor2) movie.add_genre(genre1) movie.add_genre(genre2) elif movie_key == 3: movie.director = director2 movie.add_actor(actor1) movie.add_actor(actor2) movie.add_genre(genre1) movie.add_genre(genre2) elif movie_key == 4: movie.director = director2 movie.add_actor(actor1) movie.add_actor(actor2) movie.add_genre(genre1) movie.add_genre(genre2) moive_list.append(movie) print(movie, "in MemoryRepository", movie.director) return moive_list
def movie(): mv = Movie("test", 2016) mv.add_actor(Actor('actor1')) mv.director = Director('director1') return mv