Ejemplo n.º 1
0
    def get_movies_by_year(self, target_year) -> List[Movie]:
        if target_year < 1900:
            target_year = 1900
        target_movie = Movie(
            year=int(target_year),
            title="x",
        )
        matching_movies = list()

        try:
            index = self.movie_index(target_movie)
            for movie in self._movies[index:None]:
                if movie.release_year == target_year:
                    matching_movies.append(movie)
                else:
                    break
        except ValueError:
            # No movies for specified year. Simply return an empty list.
            pass

        return matching_movies
Ejemplo n.º 2
0
def dict_to_movie(dict):
    movie = Movie(dict.rank, dict.release_year, dict.title)
    # Note there's no reviews or genres.
    return movie
Ejemplo n.º 3
0
def make_review(review_text: str, movie: Movie, user: User, time):
    review = Review(movie, review_text, user, time)
    user.add_review(review)
    movie.add_review(review)

    return review
Ejemplo n.º 4
0
def load_movies_and_genre(data_path: str, repo: memoryRepository):
    genres = dict()
    actors = dict()
    directors = dict()

    for data_row in read_csv_file(
            os.path.join(data_path, 'Data1000MoviesWithImage')):
        movie_genre = data_row[2].split(",")
        movie_actor = data_row[5].split(",")
        movie_actor = map(lambda x: x.strip(), movie_actor)
        movie_genre = map(lambda x: x.strip(), movie_genre)
        director = data_row[4]

        # Create Movie object.
        movie = Movie(data_row[1], int(data_row[6]))

        movie.rank = int(data_row[0])
        movie.description = data_row[3]
        movie.metascore = data_row[11]
        movie.votes = int(data_row[9])
        movie.rating = float(data_row[8])

        if director not in directors:
            directors[director] = list()
        directors[director].append(movie.rank)

        # Add the Movie to the repository.
        repo.add_movie(movie)

        if data_row[-1] and data_row[-1] != 'N/A':
            movie.poster = data_row[-1]

        for genre in movie_genre:
            if genre not in genres.keys():
                genres[genre] = list()
            genres[genre].append(movie.rank)

        for actor in movie_actor:
            if actor not in actors.keys():
                actors[actor] = list()
            actors[actor].append(movie.rank)

    for director_name in directors.keys():
        director = Director(director_name)
        for rank in directors[director_name]:
            movie = repo.get_movie(rank)
            director.movies = movie
            movie.director = director
        if director not in repo.directors:
            repo.directors = director

    for genre_name in genres.keys():
        genre = Genre(genre_name)
        for rank in genres[genre_name]:
            movie = repo.get_movie(rank)
            genre.genre_movies = movie
            movie.genres = genre
        if genre not in repo.genres:
            repo.genres = genre

    for actor_name in actors.keys():
        actor = Actor(actor_name)
        for rank in actors[actor_name]:
            movie = repo.get_movie(rank)
            actor.movies = movie
            movie.actors = actor
        if actor not in repo.actor:
            repo.actor = actor
Ejemplo n.º 5
0
def movie():
    return Movie("Guardians of the Galaxy", 2014)
Ejemplo n.º 6
0
def test_genre_construction(genre):
    assert genre.genre_name == "Action"

    for movie in genre.genre_movies:
        assert False
    assert not genre.is_applied_to(Movie("a", 2014))
Ejemplo n.º 7
0
def test_movie_comparison():
    movie1 = Movie("a", 2012)
    movie2 = Movie("a", 2011)
    assert movie2 < movie1
def test_repository_can_add_movie(in_memory_repo):
    movie = Movie("abc", 2016)
    movie.rank = 12
    in_memory_repo.add_movie(movie)

    assert in_memory_repo.get_movie(12) is movie