Ejemplo n.º 1
0
def test_movie():
    # check_boolean_equality_function
    movie = Movie("Moana", 2009)
    print(movie)

    movie3 = Movie("Moana", 2010)
    print(movie3)

    movie2 = Movie("Inception", 2010)
    print(movie2)

    print(movie > movie2)
    print(movie < movie3)
    print(movie3 == movie3)

    # check_remove_actor_in_list_of_actors
    actors = [Actor("Auli'i Cravalho"), Actor("Dwayne Johnson"), Actor("Rachel House"), Actor("Temuera Morrison")]
    for actor in actors:
        movie.add_actor(actor)
    movie.remove_actor(Actor("Auli'i Cravalho"))
    print(movie.actors)

    # check_for_out_of_range_runtime
    movie.runtime_minutes = 121
    print("Movie runtime: {} minutes".format(movie.runtime_minutes))

    movie.external_rating = 30
    print("votes: {}".format(movie.external_rating))
    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:
                self.movies.append(row['Title'])
                self.actors.append(row['Actors'])
                self.genres.append(row['Genre'])
                self.directors.append(row['Director'])
                self.year.append(int(row['Year']))
                self.description.append(row['Description'])
                self.runtime.append(row['Runtime (Minutes)'])
                self.external_ratings.append(row['Rating'])
                self.votes.append(row['Votes'])
                self.metascores.append(row['Metascore'])
                self.revenues.append(row['Revenue (Millions)'])

            index = 0
            for mov in self.movies:
                mov = mov.split(',')
                mov = " ".join(mov)

                movie = Movie(mov, self.year[index])
                if movie not in self.dataset_of_movies:
                    self.dataset_of_movies.append(movie)
                    movie.description = self.description[index]
                    movie.director = Director(self.directors[index])
                    for genre in self.genres[index].split(','):
                        movie.add_genre(Genre(genre))
                    for actor in self.actors[index].split(','):
                        movie.add_actor(Actor(actor))
                    if self.runtime == 'N/A':
                        pass
                    else:
                        movie.runtime_minutes = int(self.runtime[index])
                    if self.external_ratings == "N/A":
                        pass
                    else:
                        movie.external_rating = float(
                            self.external_ratings[index])
                    if self.revenues[index] == "N/A":
                        pass
                    else:
                        movie.revenue = float(self.revenues[index])
                    if self.metascores[index] == "N/A":
                        pass
                    else:
                        movie.metascore = int(self.metascores[index])
                else:
                    pass
                index += 1

            for actor in self.actors:
                list_actors = actor.split(',')
                for act in list_actors:
                    act = act.split()
                    act = " ".join(act)
                    if Actor(act) not in self.dataset_of_actors:
                        self.dataset_of_actors.append(Actor(act))
                    else:
                        pass

            for genre in self.genres:
                list_genre = genre.split(',')
                for gen in list_genre:
                    gen = gen.split()
                    gen = " ".join(gen)
                    if Genre(gen) not in self.dataset_of_genres:
                        self.dataset_of_genres.append(Genre(gen))
                    else:
                        pass

            for director in self.directors:
                list_directors = director.split(',')
                for dir in list_directors:
                    dir = dir.split()
                    dir = " ".join(dir)
                    if Director(dir) not in self.dataset_of_directors:
                        self.dataset_of_directors.append(Director(dir))
                    else:
                        pass