def test_movie_less_than_operator(): movie_1 = Movie(date.fromisoformat('2020-03-15'), "None", "None", "None", "None", 0.0, "None", 0, 0, "None", []) movie_2 = Movie(date.fromisoformat('2020-04-20'), "None", "None", "None", "None", 0.0, "None", 0, 0, "None", []) assert movie_1 < movie_2
def load_movies(data_path: str, repo: MemoryRepository): dataset_of_movies: list = [] dataset_of_actors: set = set() dataset_of_directors: set = set() dataset_of_genres: set = set() index = 0 for row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')): rank = row[0] title = row[1] description = row[3] year = int(row[6]) rating = row[8] actors = row[5] actors = actors.split(",") for x in range(0, len(actors)): actors[x] = actors[x].strip() if (actors[x] not in dataset_of_actors): actor = Actor(actors[x]) dataset_of_actors.add(actor) repo.add_actor(actor) # directors = row[4] if (directors not in dataset_of_directors): director = Director(directors) dataset_of_directors.add(director) repo.add_director(director) # genres = row[2] genres = genres.split(",") for x in range(0, len(genres)): genres[x] = genres[x].strip() if (genres[x] not in dataset_of_genres): genre = Genre(genres[x]) dataset_of_genres.add(genre) repo.add_genre(genre) # #print(f"Movie {index} with title: {title}, release year {release_year}") index += 1 movie = Movie(rank, title, year, description, director, actors, genre, rating) dataset_of_movies.append(movie) movie = Movie(rank=row[0], title=row[1], year=int(row[6]), description=row[3], director=row[4], actors=row[5], genre=row[3], rating=row[8]) repo.add_movie(movie)
def dict_to_movie(dict): movie = Movie(dict.title, dict.year) movie.id = dict.id movie.description = dict.descrption movie.reviews = dict.reviews movie.director = dict.director movie.acotrs = dict.actors movie.genres = dict.genres return movie
def test_genre_construction(genre): assert genre.genre_name == 'Mystery' for movie in genre.genreged_movies: assert False assert not genre.is_applied_to( Movie(date.fromisoformat('2020-04-20'), "None", "None", "None", "None", 0.0, "None", 0, 0, "None", []))
def movie(): return Movie( date.fromisoformat('2020-03-15'), 'test movie', 'test movie fp', 'nan', 'imglink', 7.6, "imagelink", None, 101, "jamesbrown", ["ben", "dover"], )
def test_repository_can_add_movie(in_memory_repo): movie = Movie( date.fromisoformat('2020-03-15'), 'test movie', 'test movie fp', 'nan', 'imglink', 7.6, "imagelink", 7, 101, "jamesbrown", ["ben", "dover"], ) in_memory_repo.add_movie(movie) assert in_memory_repo.get_movie(7) is movie
def get_sorted_movies_by_year(self, target_year: int) -> List[Movie]: target_movie = Movie(rank=None, title=None, year=target_year, description=None, director=None, actors=None, genre=None, rating=None) matching_movies = list() try: index = self.movie_index(target_movie) for movie in self._movies[index:None]: if movie.year == target_year: matching_movies.append(movie) else: break except ValueError: pass return matching_movies
def get_movies_by_date(self, target_date: date) -> List[Movie]: target_movie = Movie(date=target_date, title=None, first_para=None, hyperlink=None, image_hyperlink=None, rating=None) matching_movies = list() try: index = self.movie_index(target_movie) for movie in self._movies[index:None]: if movie.date == target_date: matching_movies.append(movie) else: break except ValueError: # No movies for specified date. Simply return an empty list. pass # return matching_movies return self._movies
def load_movies_and_genres(data_path: str, repo: MemoryRepository): genres = dict() for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')): movie_key = int(data_row[0]) movie_genres = data_row[2].split(",") # Add any new genres; associate the current movie with genres. for genre in movie_genres: if genre not in genres.keys(): genres[genre] = list() genres[genre].append(movie_key) # Create Movie object. movie = Movie(date=date.fromisoformat(data_row[12]), title=data_row[1], first_para=data_row[3], hyperlink="nan", image_hyperlink=data_row[14], id=movie_key, rating=data_row[8], back_hyperlink=data_row[13], runtime=int(data_row[7]), director=data_row[4], actors=data_row[5].split(",")) # Add the Movie to the repository. repo.add_movie(movie) # Create Genre objects, associate them with Movies and add them to the repository. for genre_name in genres.keys(): genre = Genre(genre_name) for movie_id in genres[genre_name]: movie = repo.get_movie(movie_id) make_genre_association(movie, genre) repo.add_genre(genre)
def article(): return Movie(title='The Equalizer', release_year=2019)
def test_repository_can_add_article(in_memory_repo): article = Movie(title='Lone Survivor', release_year=2019) in_memory_repo.add_article(article) assert in_memory_repo.get_movies_by_title('Lone Survivor') is article
def dict_to_movie(dict): movie = Movie(dict.id, dict.date, dict.title, dict.first_para, dict.hyperlink) # Note there's no reviews or genres. return movie
def test_repository_can_add_and_get_movie(in_memory_repo): movie1 = Movie("super cool movie", 2020) in_memory_repo.add_movie(movie1) assert in_memory_repo.get_movie(1001) is movie1
def test_review(self): movie1 = Movie("super cool movie", 2020) text = "wow this is a super cool movie" user1 = User("cooldude", "ABcd1234") review1 = Review(movie1, text, user1, 8) assert review1.review_text == "wow this is a super cool movie"
def test_movie(self): movie1 = Movie("super cool movie", 2020) assert repr(movie1) == "<Movie super cool movie, 2020>"
def load_movies_and_genres(data_path: str, repo: MemoryRepository): genres_list = [] file_path = os.path.join(data_path, 'image_link.json') f = open(file_path, 'r') image_link = json.load(f) for data_row in read_csv_file(os.path.join(data_path, 'Data1000Movies.csv')): movie_title = data_row[1] movie_year = int(data_row[6]) geners = data_row[2].split(',') director = data_row[4] actors = data_row[5].split(',') description = data_row[3] runtime_minutes = int(data_row[7]) genres_list.extend(geners) genres_list = list(set(genres_list)) # Add any new tags; associate the current article with tags. # Create Article object. movie = Movie(title=movie_title, release_year=movie_year) if movie_title in image_link.keys(): movie.image_hyperlink = image_link[movie_title] else: movie.image_hyperlink = 'https://m.media-amazon.com/images/M/MV5BNTY3NTY3ODAzOF5BMl5BanBnXkFtZTcwMTI4MDQyOA@@._V1_SX300.jpg' if movie.image_hyperlink == None: movie.image_hyperlink = 'https://m.media-amazon.com/images/M/MV5BNTY3NTY3ODAzOF5BMl5BanBnXkFtZTcwMTI4MDQyOA@@._V1_SX300.jpg' movie.director = Director(director) movie.runtime_minutes = runtime_minutes movie.description = description movie.comments.append("This is first comments") for actor in actors: movie.add_actor(Actor(actor)) for gener in geners: movie.add_genre(Genre(gener)) # Add the Article to the repository. repo.add_movie(movie) for gener_name in genres_list: repo.add_genre(Genre(gener_name))