Пример #1
0
def test_change_description():
    movie1 = Movie("Spirited Away", 2000)
    movie2 = Movie("Your Name", 2000)
    movie3 = Movie("Batman", 2000)
    movie4 = Movie(None, None)

    movie1.description = "Best movie"
    movie2.description = ""
    movie3.description = 123124124
    movie4.description = None

    assert movie1.description == "Best movie"
    assert movie2.description == ""
    assert movie3.description == ""
    assert movie4.description == ""
Пример #2
0
def test_movies():
    movie_file_reader = MovieFileCSVReader('test.csv')
    movie_file_reader.read_csv_file()
    movie1 = Movie("Guardians of the Galaxy", 2014)
    movie1.description = "A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe."
    movie1.runtime_minutes = 121
    movie1.votes = 757074
    movie1.rating = 8.1
    movie1.add_genre(Genre("Action"))
    movie1.add_genre(Genre("Adventure"))
    movie1.add_genre(Genre("Sci-Fi"))
    movie1.add_actor(Actor("Chris Pratt"))
    movie1.add_actor(Actor("Vin Diesel"))
    movie1.add_actor(Actor("Bradley Cooper"))
    movie1.add_actor(Actor("Zoe Saldana"))
    movie1.director = Director("James Gunn")
    assert movie_file_reader.dataset_of_movies[0] == movie1
    assert movie_file_reader.dataset_of_movies[0].runtime_minutes == movie1.runtime_minutes
    assert movie_file_reader.dataset_of_movies[0].description == movie1.description
    assert movie_file_reader.dataset_of_movies[0].votes == movie1.votes
    assert movie_file_reader.dataset_of_movies[0].rating == movie1.rating
    assert movie_file_reader.dataset_of_movies[0].actors == movie1.actors
    assert movie_file_reader.dataset_of_movies[0].genres == movie1.genres
    assert movie_file_reader.dataset_of_movies[0].director == movie1.director
    assert movie_file_reader.dataset_of_actors[0] == Actor("Chris Pratt")
    assert movie_file_reader.dataset_of_actors[1] == Actor("Vin Diesel")
    assert movie_file_reader.dataset_of_actors[2] == Actor("Bradley Cooper")
    assert movie_file_reader.dataset_of_actors[3] == Actor("Zoe Saldana")
    assert repr(movie_file_reader.dataset_of_actors[0].actor_colleague_list) == "[<Actor Vin Diesel>, <Actor Bradley Cooper>, <Actor Zoe Saldana>, <Actor Jennifer Lawrence>, <Actor Michael Sheen>, <Actor Laurence Fishburne>, <Actor Denzel Washington>, <Actor Ethan Hawke>, <Actor Vincent D'Onofrio>, <Actor Bryce Dallas Howard>, <Actor Ty Simpkins>, <Actor Judy Greer>, <Actor Will Ferrell>, <Actor Elizabeth Banks>, <Actor Will Arnett>, <Actor Jessica Chastain>, <Actor Joel Edgerton>, <Actor Mark Strong>, <Actor Channing Tatum>, <Actor Rosario Dawson>, <Actor Jenna Dewan Tatum>]"
    assert movie_file_reader.dataset_of_directors[0] == Director("James Gunn")
    assert movie_file_reader.dataset_of_genres[0] == Genre("Action")
    assert movie_file_reader.dataset_of_genres[1] == Genre("Adventure")
    assert movie_file_reader.dataset_of_genres[2] == Genre("Sci-Fi")
Пример #3
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)

            index = 0
            for row in movie_file_reader:
                title = row['Title']
                release_year = int(row['Year'])
                movie = Movie(title, release_year)
                for actor in row['Actors'].split(","):
                    actor = Actor(actor.strip())
                    if actor not in self.__actors:
                        self.__actors.add(actor)
                    movie.add_actor(actor)

                director = Director(row['Director'].strip())
                if director not in self.__directors:
                    self.__directors.add(director)
                movie.director = director

                for genre in row['Genre'].split(','):
                    genre = Genre(genre.strip())
                    if genre not in self.__genres:
                        self.__genres.add(genre)
                    movie.add_genre(genre)

                movie.runtime_minutes = row["Runtime (Minutes)"]
                movie.description = row["Description"]

                self.__movies.append(movie)

                index += 1
Пример #4
0
 def test_movie_set_director(self):
     movie = Movie("Moana", 2016)
     movie.description = "   This is a movie   "
     assert movie.description == "This is a movie"
     movie.director = Director("Ron Clements")
     assert movie.director.director_full_name is "Ron Clements"
     assert repr(movie.director) == "<Director Ron Clements>"
Пример #5
0
    def test_setters(self): # inherently tests getters too
        a_movie = Movie("Back To The Future", 1965)
        director1 = Director("Brad Bird")

        a_movie.title = "  Mission Impossible: Ghost Protocol  "
        assert a_movie.title == "Mission Impossible: Ghost Protocol"
        a_movie.title = 15
        #assert a_movie.title == "Mission Impossible: Ghost Protocol"

        a_movie.description = "  An action movie  "
        assert a_movie.description == "An action movie"

        a_movie.director = director1
        assert a_movie.director == director1

        actor1 = Actor("Tom Cruise")
        actor2 = Actor("Simon Pegg")
        a_movie.actors = [actor1, actor2]
        assert a_movie.actors == [actor1, actor2]

        genre1 = Genre("Action")
        genre2 = Genre("Comedy")
        a_movie.genres = [genre1, genre2]
        assert a_movie.genres == [genre1, genre2]

        a_movie.runtime_minutes = 100
        assert a_movie.runtime_minutes == 100
        assert type(a_movie.runtime_minutes) == int
        with pytest.raises(ValueError):
            a_movie.runtime_minutes = 0
            a_movie.runtime_minutes = -10
Пример #6
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:
                title = row['Title']
                release_year = int(row['Year'])
                movie = Movie(title, release_year)
                movie.votes = row['Votes']
                movie.metascore = row['Metascore']
                movie.rating = row['Rating']
                movie.description = row['Description']
                self.__movies.append(movie)
                director = Director(row['Director'])
                if director not in self.__directors:
                    self.__directors.append(director)
                actors = re.split(", |,", row["Actors"])
                for actor_splited in actors:
                    actor = Actor(actor_splited)
                    if actor not in self.__actors:
                        self.__actors.append(actor)
                genres = row['Genre'].split(",")
                for genre_splited in genres:
                    genre = Genre(genre_splited)
                    if genre not in self.__genres:
                        self.__genres.append(genre)
Пример #7
0
    def test_movie_runtime(self):
        movie = Movie("Moana", 2016)
        movie.description = "   This is a movie   "
        assert movie.description == "This is a movie"
        movie.director = Director("Ron Clements")
        assert movie.director.director_full_name is "Ron Clements"
        assert repr(movie.director) == "<Director Ron Clements>"

        actors = [
            Actor("Auli'i Cravalho"),
            Actor("Dwayne Johnson"),
            Actor("Rachel House"),
            Actor("Temuera Morrison")
        ]
        for actor in actors:
            movie.add_actor(actor)
        assert repr(
            movie.actors
        ) == "[<Actor Auli\'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"
        movie.remove_actor(Actor("Dwayne Johnson"))
        assert repr(
            movie.actors
        ) == "[<Actor Auli\'i Cravalho>, <Actor Rachel House>, <Actor Temuera Morrison>]"

        genres = [Genre("Animated"), Genre("Comedy")]
        for genre in genres:
            movie.add_genre(genre)
        assert repr(movie.genres) == "[<Genre Animated>, <Genre Comedy>]"
        movie.remove_genre(Genre("Comedy"))
        assert repr(movie.genres) == "[<Genre Animated>]"

        movie.runtime_minutes = 100
        assert movie.runtime_minutes is 100
Пример #8
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.description = row['Description']
                movie.runtime_minutes = int(row['Runtime (Minutes)'])

                director = Director(row['Director'])
                self.__dataset_of_directors.add(director)
                movie.director = director

                parsed_genres = row['Genre'].split(',')
                for genre_string in parsed_genres:
                    genre = Genre(genre_string)
                    self.__dataset_of_genres.add(genre)
                    movie.add_genre(genre)

                parsed_actors = row['Actors'].split(',')
                for actor_string in parsed_actors:
                    actor = Actor(actor_string)
                    self.__dataset_of_actors.add(actor)
                    movie.add_actor(actor)

                self.__dataset_of_movies.append(movie)
Пример #9
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:
                title = row['Title']
                release_year = int(row['Year'])
                movie = Movie(title, release_year)
                self.__dataset_of_movies.append(movie)
                actors = row["Actors"]
                actors = actors.split(",")
                for actor in actors:
                    actor = Actor(actor)
                    movie.add_actor(actor)

                    if actor not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(actor)

                director = Director(row["Director"])
                movie.director = director

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

                genres = row["Genre"]
                genres = genres.split(",")
                for genre in genres:
                    genre = Genre(genre)
                    movie.add_genre(genre)

                    if genre not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(genre)

                movie.description = row["Description"]
                movie.runtime_minutes = row["Runtime (Minutes)"]
Пример #10
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:
                try:
                    rank = int(row['Rank'])
                except ValueError:
                    rank = None
                title = row['Title']
                genres = row['Genre'].split(',')
                description = row['Description']
                actors = row['Actors'].split(',')
                try:
                    release_year = int(row['Year'])
                except ValueError:
                    release_year = None
                try:
                    run_time = int(row['Runtime (Minutes)'])
                except ValueError:
                    run_time = None
                try:
                    rating = int(row['Rating'])
                except ValueError:
                    rating = 0
                try:
                    votes = int(row['Votes'])
                except ValueError:
                    votes = 0
                director = Director(row['Director'])
                try:
                    revenue = float(row['Revenue (Millions)'])
                except ValueError:
                    revenue = None
                try:
                    metascore = int(row['Metascore'])
                except ValueError:
                    metascore = None

                mov = Movie(title, release_year)
                mov.director = director
                mov.description = description
                mov.metascore = metascore
                mov.rank = rank
                mov.runtime_minutes = run_time
                mov.rating = rating
                mov.votes = votes
                mov.revenue = revenue

                self.load_actors(mov, actors)

                if director not in self.__directors:
                    self.__directors.add(director)

                self.load_genres(mov, genres)

                if mov not in self.__movies:
                    self.__movies.append(mov)
Пример #11
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)

            index = 0
            for row in movie_file_reader:
                title = row["Title"]
                release_year = int(row["Year"])
                movie = Movie(title, release_year)

                movie.description = row["Description"]

                director = row["Director"]
                movie.director = director
                if Director(director) not in self.__dataset_of_directors:
                    self.__dataset_of_directors.append(Director(director))

                actors = row["Actors"].split(",")
                for actor in actors:
                    movie.add_actor(Actor(actor))
                    if Actor(actor) not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(Actor(actor))

                genres = row["Genre"].split(",")
                for genre in genres:
                    movie.add_genre(Genre(genre))
                    if Genre(genre) not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(Genre(genre))

                movie.runtime_minutes = int(row["Runtime (Minutes)"])

                try:
                    movie.external_rating = float(row["Rating"])
                except ValueError:
                    pass

                try:
                    movie.rating_votes = int(row["Votes"])
                except ValueError:
                    pass

                try:
                    movie.revenue_in_millions = float(row["Revenue (Millions)"])
                except ValueError:
                    pass

                try:
                    movie.metascore = int(row["Metascore"])
                except ValueError:
                    pass

                self.__dataset_of_movies.append(movie)
                # title = row['Title']
                # release_year = int(row['Year'])
                # print(f"Movie {index} with title: {title}, release year {release_year}")
                index += 1
Пример #12
0
    def _read_row(self, row: _ROW) -> Movie:
        """
        Helper method to construct a Movie from a row.

        Raises:
            ValueError: unable to parse row: {row}
         """
        error = False

        try:
            title = row['Title']
            genres = [
                self._get_genre(Genre(name))
                for name in row['Genre'].split(',')
            ]
            description = row['Description']
            director = self._get_director(Director(row['Director']))
            actors = [
                self._get_actor(Actor(name))
                for name in row['Actors'].split(',')
            ]
            release_year = int(row['Year'])
            runtime_minutes = int(row['Runtime (Minutes)'])
            rating = float(row['Rating'])
            votes = int(row['Votes'])
            revenue_millions = float(
                row['Revenue (Millions)']
            ) if row['Revenue (Millions)'] != 'N/A' else None
            metascore = int(
                row['Metascore']) if row['Metascore'] != 'N/A' else None
        except KeyError:
            error = True
        except ValueError:
            error = True

        if error:
            raise ValueError(f'unable to parse row: {row}')

        movie = Movie(title, release_year)
        movie.genres = genres
        movie.description = description
        movie.director = director
        movie.actors = actors
        movie.runtime_minutes = runtime_minutes
        movie.rating = rating
        movie.votes = votes

        if revenue_millions:
            movie.revenue_millions = revenue_millions

        if metascore:
            movie.metascore = metascore

        return movie
Пример #13
0
 def create_movie_instance(self, row):
     movie = Movie(row["Title"], int(row["Year"]))
     movie.director = Director(row["Director"])
     movie.runtime_minutes = int(row["Runtime (Minutes)"])
     movie.actors = [
         Actor(actor.strip()) for actor in row['Actors'].split(",")
     ]
     movie.genres = [
         Genre(genre.strip()) for genre in row['Genre'].split(",")
     ]
     movie.description = row["Description"]
     return movie
Пример #14
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)
         index = 0
         for row in movie_file_reader:
             try:
                 movie = Movie(row['Title'], int(row['Year']))
             except ValueError:
                 print("Invalid release year")
             else:
                 director = Director(row['Director'].strip())
                 actors = row['Actors'].split(",")
                 genres = row['Genre'].split(",")
                 movie.director = director
                 if director not in self.__dataset_of_directors:
                     self.__dataset_of_directors.append(director)
                 movie.description = row['Description'].strip()
                 for actor_name in actors:
                     actor_name = actor_name.strip()
                     actor = Actor(actor_name.strip())
                     if actor in self.dataset_of_actors:
                         i = self.dataset_of_actors.index(actor)
                         actor = self.dataset_of_actors[i]
                     else:
                         self.__dataset_of_actors.append(actor)
                     for actor1_name in actors:
                         actor1_name = actor1_name.strip()
                         if not actor.check_if_this_actor_worked_with(Actor(actor1_name)) and (actor_name != actor1_name):
                             actor.add_actor_colleague(Actor(actor1_name))
                     movie.add_actor(actor)
                 for genre_name in genres:
                     genre = Genre(genre_name.strip())
                     movie.add_genre(genre)
                     if genre not in self.__dataset_of_genres:
                         self.__dataset_of_genres.append(genre)
                 try:
                     movie.runtime_minutes = int(row['Runtime (Minutes)'])
                 except ValueError:
                     movie.runtime_minutes = None
                 try:
                     movie.votes = int(row['Votes'])
                 except ValueError:
                     movie.votes = None
                 try:
                     movie.rating = float(row['Rating'])
                 except ValueError:
                     movie.rating = None
                 if movie not in self.__dataset_of_movies: # Check if this takes into account the same movie but different objects
                     self.__dataset_of_movies.append(movie)
             index += 1
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)

            index = 0
            for row in movie_file_reader:
                title = row['Title']
                release_year = int(row['Year'])
                #print(f"Movie {index} with title: {title}, release year {release_year}")
                m = Movie(title, release_year)
                m.description = row['Description']

                director = Director(row['Director'])
                try:
                    # if director exists, assign the same director object to the movie
                    index = self.dataset_of_directors.index(director)
                    director = self.dataset_of_directors[index]
                except ValueError:
                    self.dataset_of_directors.append(director)
                m.director = director

                m.votes = int(row['Votes'])
                m.rating = float(row['Rating'])
                m.runtime_minutes = int(row['Runtime (Minutes)'])
                if row['Metascore'] != 'N/A':
                    m.metascore = float(row['Metascore'])
                if row['Revenue (Millions)'] != 'N/A':
                    m.revenue = float(row['Revenue (Millions)'])

                for g in row['Genre'].split(","):
                    genre = Genre(g)
                    try:
                        index = self.dataset_of_genres.index(genre)
                        genre = self.dataset_of_genres[index]
                    except ValueError:
                        self.dataset_of_genres.append(genre)
                    m.add_genre(genre)

                for a in row['Actors'].split(","):
                    actor = Actor(a)
                    try:
                        index = self.dataset_of_actors.index(actor)
                        actor = self.dataset_of_actors[index]
                    except ValueError:
                        self.dataset_of_actors.append(actor)
                    m.add_actor(actor)

                if m not in self.dataset_of_movies:
                    self.dataset_of_movies.append(m)
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader_genre = csv.DictReader(csvfile)

            for row in movie_file_reader_genre:
                movie = row['Title']
                actors = sorted(row['Actors'].strip().split(','))
                for i in range(len(actors)):
                    actors[i] = actors[i].strip()
                director = row['Director']
                genres = sorted(row['Genre'].strip().split(','))
                for i in range(len(genres)):
                    genres[i] = genres[i].strip()
                year = int(row['Year'].strip())
                description = row['Description'].strip()
                runtime = int(row['Runtime (Minutes)'].strip())

                if self.__genre_type in genres:
                    the_movie = Movie(movie, year)

                    the_director = Director(director)
                    the_movie.director = the_director

                    for i in range(len(actors)):
                        the_actor = Actor(actors[i])
                        the_movie.actors.append(the_actor)

                    the_movie.description = description
                    the_movie.runtime_minutes = runtime
                    the_movie.director = the_director

                    for i in range(len(genres)):
                        the_genre = Genre(genres[i])
                        the_movie.genres.append(the_genre)

                    if the_movie not in self.__dataset_of_movies:
                        flag = True
                        for i in range(len(self.__dataset_of_movies)):
                            if the_movie < self.__dataset_of_movies[i]:
                                self.__dataset_of_movies.insert(i, the_movie)
                                flag = False
                                break
                        if flag:
                            self.__dataset_of_movies.insert(i, the_movie)

            self.__dataset_of_movies.pop()
Пример #17
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)

            index = 0
            for row in movie_file_reader:
                title = row['Title']
                genres = row['Genre']
                description = row['Description']
                release_year = int(row['Year'])
                director = row["Director"]
                actors = row["Actors"]
                runtime = int(row["Runtime (Minutes)"])
                rating = row["Rating"]
                votes = row["Votes"]
                revenue = row["Revenue (Millions)"]
                metascore = row["Metascore"]

                #print(f"Movie {index} with title: {title}, release year {release_year}")
                #print(index, title, genre, release_year, director, actors, runtime, rating, votes, revenue, metascore)

                movie_director = Director(director)
                movie = Movie(title, release_year)
                movie.director = movie_director
                movie.description = description.strip()
                for actor in actors.split(","):
                    actor = Actor(actor)
                    movie.add_actor(actor)
                    if actor not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(actor)

                movie.runtime_minutes = runtime

                for genre in genres.split(","):
                    genre = Genre(genre)
                    movie.add_genre(genre)
                    if genre not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(genre)

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

                index += 1
Пример #18
0
 def test_movie_set_actors(self):
     movie = Movie("Moana", 2016)
     movie.description = "   This is a movie   "
     assert movie.description == "This is a movie"
     movie.director = Director("Ron Clements")
     assert movie.director.director_full_name is "Ron Clements"
     assert repr(movie.director) == "<Director Ron Clements>"
     actors = [
         Actor("Auli'i Cravalho"),
         Actor("Dwayne Johnson"),
         Actor("Rachel House"),
         Actor("Temuera Morrison")
     ]
     for actor in actors:
         movie.add_actor(actor)
     assert repr(
         movie.actors
     ) == "[<Actor Auli\'i Cravalho>, <Actor Dwayne Johnson>, <Actor Rachel House>, <Actor Temuera Morrison>]"
    def run_through_file(self, csv_movie_dict):
        for row in csv_movie_dict:
            movie = Movie(row['Title'], int(row['Year']))
            movie.description = row['Description']
            movie.runtime_minutes = int(row['Runtime (Minutes)'])

            director = Director(row['Director'])
            self.add_director(director, movie)

            actors = row['Actors'].split(',')
            for actor_name in actors:
                self.add_actor(actor_name, movie)

            genres = row['Genre'].split(',')
            for genre_name in genres:
                self.add_genre(genre_name, movie)

            self.add_movie(movie)
Пример #20
0
def populated_movies(genres, directors, actors):
    movies = []

    for i in range(10):
        movie = Movie(f'Movie{i}', 2000 + i)
        movie.genres = [genres[i]]
        movie.description = f'Description{i}'
        movie.director = directors[i]
        movie.actors = [actors[i]]
        movie.runtime_minutes = i + 1
        movie.rating = float(i)
        movie.votes = i

        if i % 2 == 0:
            movie.revenue_millions = float(i + 1)

        if i % 4 == 0:
            movie.metascore = i * 10

        movies.append(movie)

    return movies
    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:
                rank = row['Rank']

                # make movie from data
                movie = Movie(row['Title'], int(row['Year']))
                movie.description = row['Description']
                movie.runtime_minutes = int(row['Runtime (Minutes)'])
                movie.external_rating = float(
                    row['Rating']) if row['Rating'] != "N/A" else None
                movie.rating_votes = int(
                    row['Votes']) if row['Votes'] != "N/A" else None
                movie.revenue = float(
                    row['Revenue (Millions)']
                ) if row['Revenue (Millions)'] != "N/A" else None
                movie.metascore = int(
                    row['Metascore']) if row['Metascore'] != "N/A" else None

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

                movie.director = director
                self._directors.add(director)

                for actor in actors:
                    actor = Actor(actor)
                    movie.add_actor(actor)
                    self._actors.add(actor)

                for genre in genres:
                    genre = Genre(genre)
                    movie.add_genre(genre)
                    self._genres.add(genre)

                self.dataset_of_movies.add(movie)
Пример #22
0
 def read_csv_file(self):
     csv_file_contents = csv.reader(open(self.__file_name, mode='r', encoding='utf-8-sig'))
     boolean = True
     for row in csv_file_contents:
         if boolean:
             boolean = False
             continue
         temp_movie = Movie("","")
         temp_movie.id = int(row[0])-1
         temp_movie.title = row[1]
         genre_list = row[2].split(",")
         genre_list = [Genre(genre) for genre in genre_list]
         temp_movie.genres = genre_list
         temp_movie.description = row[3]
         temp_movie.director = Director(row[4])
         actor_list = row[5].split(",")
         actor_list = [Actor(actor) for actor in actor_list]
         temp_movie.actors = actor_list
         temp_movie.releaseDate = int(row[6])
         temp_movie.runtime_minutes = int(row[7])
         temp_movie.rating = float(row[8])
         temp_movie.metascore = row[11]
         self.movie_full_details.append(temp_movie)
Пример #23
0
 def read_csv_file(self) -> None:
     with open(self.__filename, mode='r',
               encoding='utf-8-sig') as file_data:
         reader = csv.DictReader(file_data)
         self.__dataset_of_movies = list()
         for row in reader:
             new_movie = Movie(row['Title'], int(row['Year']))
             new_movie.description = row['Description']
             new_movie.genres = [
                 Genre(i.strip()) for i in row['Genre'].split(',')
             ]
             new_movie.actors = [
                 Actor(i.strip()) for i in row['Actors'].split(',')
             ]
             new_movie.director = Director(row['Director'].strip())
             if row['Runtime (Minutes)'].isdigit():
                 new_movie.runtime_minutes = int(row['Runtime (Minutes)'])
             self.__dataset_of_movies.append(new_movie)
             for i in new_movie.genres:
                 self.add_genre(i)
                 self.__dataset_of_genres[i].append(new_movie)
             for i in new_movie.actors:
                 self.add_actor(i)
             self.add_director(new_movie.director)
Пример #24
0
def test_desc():
    m2 = Movie("the Jedi would tell you.", 2010)
    m2.description = " It's a Sith Legend.  "
    assert m2.description == "It's a Sith Legend."
Пример #25
0
 def test_movie_set_description(self):
     movie = Movie("Moana", 2016)
     movie.description = "   This is a movie   "
     assert movie.description == "This is a movie"
Пример #26
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)

            self.__dataset_of_movies = list()
            self.__dataset_of_actors = list()
            self.__dataset_of_directors = list()
            self.__dataset_of_genres = list()

            index = 0
            for row in movie_file_reader:
                title = row['Title'].strip()  # stripping to safe
                release_year = int(row['Year'])
                actor_full_name_list = get_list_from_comma_string(
                    row['Actors'])
                director_full_name = row['Director'].strip(
                )  # stripping to safe
                genre_name_list = get_list_from_comma_string(row['Genre'])

                #- other things
                rank = int(row['Rank'])
                description = row['Description']
                runtime_minutes = int(row['Runtime (Minutes)'])
                external_rating = float(row['Rating'])
                external_rating_votes = int(row['Votes'])

                # These require try/except because some values are N/A's (preferably all would but it's SUPER ugly code)
                try:
                    revenue = float(row['Revenue(Millions)'])
                except:
                    revenue = None
                try:
                    metascore = int(row['Metascore'])
                except:
                    metascore = None

                #-------- Make Actor, Director and Genre Objects
                actor_object_list = [
                    Actor(actor_full_name)
                    for actor_full_name in actor_full_name_list
                ]
                director_object = Director(director_full_name)
                genre_object_list = [
                    Genre(genre_name) for genre_name in genre_name_list
                ]

                #-------- Create and set up Movie Object
                movie_object = Movie(title, release_year)
                movie_object.actors = actor_object_list  # thanks to my setter implementation
                movie_object.director = director_full_name
                movie_object.genres = genre_object_list  # ^ ditto
                movie_object.release_year = release_year

                #- other things
                movie_object.description = description
                movie_object.runtime_minutes = runtime_minutes
                movie_object.external_rating = external_rating
                movie_object.external_rating_votes = external_rating_votes
                if revenue != None:
                    movie_object.revenue = revenue
                if metascore != None:
                    movie_object.metascore = metascore

                #-------- Take all the above information, and add to datasets
                self.__dataset_of_movies.append(
                    movie_object
                )  # the assumption is that each row in the csv is a unique movie

                # I could create a function that adds unique things to lists only, nvm
                for actor_object in actor_object_list:
                    if actor_object not in self.__dataset_of_actors:
                        self.__dataset_of_actors.append(actor_object)

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

                for genre_object in genre_object_list:
                    if genre_object not in self.__dataset_of_genres:
                        self.__dataset_of_genres.append(genre_object)

                index += 1


# To test my assigmnent, run the following lines of code (I have copy and pasted these in my test_all.py file too)

#movie_file_csv_reader_object = MovieFileCSVReader(r"C:\Users\Nathan Longhurst\OneDrive - The University of Auckland\b Comp235\Assignment\GitHub Clone (Current)\CS235FlixSkeleton\datafiles\Data1000Movies.csv")
#unclean_dict = movie_file_csv_reader_object.check_csv_file()
#movie_file_csv_reader_object.clean_csv_file(unclean_dict)
Пример #27
0
def load_movies_and_actors_genres_director(data_path: str,
                                           repo: MemoryRepository):
    actor_dict = dict()
    genre_dict = dict()
    directors = dict()

    for data_row in read_csv_file(os.path.join(data_path,
                                               'Data1000Movies.csv')):
        movie_key = int(data_row[0])
        genres = data_row[2]
        actors = data_row[5]
        director = data_row[4]
        genre_list = genres.rsplit(",")
        actor_list = actors.rsplit(",")

        for genre in genre_list:
            if genre not in genre_dict.keys():
                genre_dict[genre] = list()
            genre_dict[genre].append(movie_key)

        for actor in actor_list:
            if actor not in actor_dict.keys():
                actor_dict[actor] = list()
            actor_dict[actor].append(movie_key)

        if director not in directors.keys():
            directors[director] = list()
        directors[director].append(movie_key)

        movie = Movie(data_row[1], int(data_row[6]))
        movie.rank = movie_key
        movie.description = data_row[3]
        movie.runtime_minutes = int(data_row[7])
        if data_row[8] != "N/A":
            movie.rating = float(data_row[8])
        if data_row[9] != "N/A":
            movie.votes = int(data_row[9])
        if data_row[10] != "N/A":
            movie.revenue = float(data_row[10])
        if data_row[11] != "N/A":
            movie.metascore = float(data_row[11])

        repo.add_movie(movie)

    for genre_name in genre_dict.keys():
        genre = Genre(genre_name)
        for movie_id in genre_dict[genre_name]:
            movie = repo.get_movie(movie_id)
            genre.add_movie(movie)
            movie.add_genre(genre)
        repo.add_genre(genre)

    for actor_name in actor_dict.keys():
        actor = Actor(actor_name)
        for movie_id in actor_dict[actor_name]:
            movie = repo.get_movie(movie_id)
            actor.add_movie(movie)
            movie.add_actor(actor)
        repo.add_actor(actor)

    for director_name in directors.keys():
        director = Director(director_name)
        for movie_id in directors[director_name]:
            movie = repo.get_movie(movie_id)
            director.add_movie(movie)
            movie.director = director
        repo.add_director(director)
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)

            index = 0
            for row in movie_file_reader:
                # read data of row into variables
                title = row['Title']

                genres_str = row['Genre'].split(",")
                genres = []
                for genre in genres_str:
                    genres.append(Genre(genre))

                year = int(row['Year'])

                description = row['Description']

                director = Director(row['Director'])

                actors_str = row['Actors'].split(",")
                actors = []
                for actor in actors_str:
                    actors.append(Actor(actor))

                runtime = row['Runtime (Minutes)']

                rating = row['Rating']

                votes = row['Votes']

                revenue = row['Revenue (Millions)']

                metascore = row['Metascore']

                # create and populate Movie obj
                movieObj = Movie(title, year)

                for genre in genres:
                    movieObj.add_genre(genre)

                movieObj.description = description

                movieObj.director = director

                for actor in actors:
                    movieObj.add_actor(actor)

                if not runtime == "N/A":
                    movieObj.runtime_minutes = int(runtime)

                if not rating == "N/A":
                    movieObj.rating = float(rating)

                if not votes == "N/A":
                    movieObj.votes = int(votes)

                if not revenue == "N/A":
                    movieObj.revenue = float(revenue)

                if not metascore == "N/A":
                    movieObj.metascore = int(metascore)

                # populate datasets
                self.dataset_of_movies.append(movieObj)

                for actor in actors:
                    if actor not in self.dataset_of_actors:
                        self.dataset_of_actors.append(actor)

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

                for genre in genres:
                    if genre not in self.dataset_of_genres:
                        self.dataset_of_genres.append(genre)

                index += 1
    def test_init(self):
        movie1 = Movie("Moana", 2016)
        assert repr(movie1) == "<Movie Moana, 2016>"
        movie2 = Movie("")
        assert movie2.title is None
        assert movie2.year is None
        movie3 = Movie(3)
        assert movie3.title is None
        movie1.director = "er"
        assert movie1.director is None
        movie4 = Movie("Moana", 2016)
        movie5 = Movie("Mn", 2017)
        assert (movie1 == movie5) == False
        assert (movie1 == movie4) == True
        assert movie1.title == "Moana"
        assert movie1.description == None
        movie1.description = 2
        assert movie1.description == None
        movie1.description = "adcsdv"
        assert movie1.description == "adcsdv"
        movie1.director = "as"
        assert movie1.director is None
        movie1.director = Director("asd")
        assert (movie1.director == Director("asd")) == True
        actors = [
            Actor("Auli'i Cravalho"),
            Actor("Dwayne Johnson"),
            Actor("Rachel House"),
            Actor("Temuera Morrison")
        ]
        for actor in actors:
            movie1.add_actor(actor)
        movie6 = Movie("as", 190)
        genres = [Genre("asdc"), Genre("dfg")]
        for genre in genres:
            movie1.add_genre(genre)
        assert (movie6 == Movie("as", None)) == True
        assert (movie6.title == "as") == True
        assert movie6.year is None

        with pytest.raises(ValueError):
            movie1.runtime_minutes = -10
        movie1.runtime_minutes = 10
        assert movie1.runtime_minutes == 10
        string1 = "a"
        assert (movie1 == 123) == False
        movie7 = Movie("a", 1900)
        movie8 = Movie("None", None)
        print(movie8.concate())
        assert (movie7 < movie8) == False
        movie1.add_actor("sasa")
        assert (movie1.actors == [
            Actor("Auli'i Cravalho"),
            Actor("Dwayne Johnson"),
            Actor("Rachel House"),
            Actor("Temuera Morrison")
        ]) == True
        movie1.remove_actor(Actor("Auli'i Cravalho"))
        assert (movie1.actors == [
            Actor("Dwayne Johnson"),
            Actor("Rachel House"),
            Actor("Temuera Morrison")
        ]) == True
        movie1.remove_actor("asd")
        assert (movie1.actors == [
            Actor("Dwayne Johnson"),
            Actor("Rachel House"),
            Actor("Temuera Morrison")
        ]) == True
        movie1.add_actor(Actor("Auli'i Cravalho"))
        assert (movie1.actors == [
            Actor("Dwayne Johnson"),
            Actor("Rachel House"),
            Actor("Temuera Morrison"),
            Actor("Auli'i Cravalho")
        ]) == True
        movie1.remove_genre(Genre("asdc"))
        assert (movie1.genres == [Genre("dfg")]) == True
        movie1.add_genre(Genre("asdc"))
        assert (movie1.genres == [Genre("dfg")]) == False
        with pytest.raises(ValueError):
            movie1.runtime_minutes = "sd"
        movie1.actors = ['a', 'b']
Пример #30
0
def test_description():
    movie1 = Movie("Moana", 2016)
    movie1.description = "fun"
    assert movie1.description == "fun"