def read_csv_file(self):
        with open(self._data_path, mode='r', encoding='utf-8-sig') as f:
            records = csv.DictReader(f)
            for record in records:
                movie = Movie(record.get('Title'), int(record.get('Year', 0)))

                for actor in self._read_field(record, 'Actors', ','):
                    actor = Actor(actor)
                    movie.add_actor(actor)
                    self._dataset_of_actors.add(actor)

                for genre in self._read_field(record, 'Genre', ','):
                    genre = Genre(genre)
                    movie.add_genre(genre)
                    self._dataset_of_genres.add(genre)

                for director in self._read_field(record, 'Director', ','):
                    director = Director(director)
                    movie.set_director(director)
                    self._dataset_of_directors.add(director)

                movie.description = record.get('Description')
                movie.runtime_minutes = int(record.get('Runtime (Minutes)'))

                self._dataset_of_movies.add(movie)
示例#2
0
    def read_csv_file(self):
        with open(self.__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.rank = int(row["Rank"])
                movie.description = str(row["Description"])

                director = Director(row["Director"])
                actors = row["Actors"].split(",")
                genres = row["Genre"].split(",")

                if movie not in self.__dataset_of_movies:
                    self.__dataset_of_movies.append(movie)

                if director not in self.__dataset_of_directors:
                    self.__dataset_of_directors.append(director)

                for i in actors:
                    actor = Actor(i)
                    if actor not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(actor)

                for i in genres:
                    genre = Genre(i)
                    if genre not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(genre)
def test_set_description():
    movie1 = Movie("Moana", 2016)
    movie1.description = "description"
    assert movie1.description == "description"
    movie1.description = ""
    assert movie1.description == "description"