Пример #1
0
def load_movies(data_path: str):
    for data_row in read_csv(os.path.join(data_path, 'Data1000Movies.csv')):
        movie = Movie(data_row[1], int(data_row[6]))
        movie.rank = int(data_row[0])
        movie.genres = load_genres(data_row[2])
        movie.description = data_row[3]
        movie.director = load_directors(data_row[4])
        movie.actors = load_actors(data_row[5])
        try:
            movie.runtime_minutes = int(data_row[7])
        except ValueError:
            movie.runtime_minutes = 0
        try:
            movie.rating = int(data_row[8])
        except ValueError:
            pass
        try:
            movie.votes = int(data_row[9])
        except ValueError:
            pass
        try:
            movie.revenue = float(data_row[10])
        except ValueError:
            pass
        try:
            movie.metascore = int(data_row[11])
        except ValueError:
            pass

        movie_data = {
            'title': data_row[1],
            'year': int(data_row[6]),
            'rank': movie.rank,
            'genres': movie.genres,
            'description': movie.description,
            'director': movie.director,
            'actors': movie.actors,
        }

        yield movie_data
    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:
                title = row['Title']
                release_year = int(row['Year'])
                description = row['Description']
                time = int(row['Runtime (Minutes)'])
                movie = Movie(title, release_year)

                actors1 = row['Actors'].split(",")
                actors2 = []
                for i in actors1:
                    actors2.append(Actor(i))

                director = Director(row['Director'])

                genres1 = row['Genre'].split(",")
                genres2 = []
                for i in genres1:
                    genres2.append(Genre(i))

                movie.director = director
                movie.description = description
                movie.actors = actors2
                movie.genres = genres2
                movie.runtime_minutes = time

                #Adding to datasets
                self.__dataset_of_movies.append(movie)

                for actor in actors2:
                    self.__dataset_of_actors.add(actor)

                self.__dataset_of_directors.add(director)

                for genre in genres2:
                    self.__dataset_of_genres.add(genre)
Пример #3
0
def movie():
    movie = Movie("Barnacle Boy", 2020)
    movie.director = "John Mack"
    movie.description = "this guy is from spongebob"
    return movie