示例#1
0
def read_csv_file(filename: str, repo: MemoryRepository):
    with open(filename, encoding='utf-8-sig') as infile:
        rows = csv.DictReader(infile)
        for row in rows:
            title = row['Title']
            description = row['Description']
            year = int(row['Year'])
            director = row['Director']
            D = Director(director.strip())
            genres = row['Genre'].split(',')
            movie = Movie(title, year)
            movie.director = D
            movie.description = description
            for genre in genres:
                G = Genre(genre.strip())
                repo.add_genre(G)
                movie.genres.append(G)
            repo.add_director(D)
            actors = row['Actors'].split(',')
            for actor in actors:
                A = Actor(actor.strip())
                repo.add_actor(A)
                movie.actors.append(A)
            #
            runtime = int(row['Runtime (Minutes)'])
            movie.runtime_minutes = runtime
            repo.add_movie(movie)
示例#2
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)
示例#3
0
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