def get_all_movie(condition, repo: AbstractRepository):
    movies = []

    if condition[0] != 'All' and condition[1] != 'All':
        movies_genre = repo.get_movies_by_genre(condition[0])
        movies_year = repo.get_movies_by_year(condition[1])
        if len(movies_year) < len(movies_genre):
            for movie in movies_year:
                if movie in movies_genre:
                    movies.append(movie)
        else:
            for movie in movies_genre:
                if movie in movies_year:
                    movies.append(movie)

    elif condition == ['All', 'All']:
        for rank in range(1, repo.get_number_of_movies() + 1):
            movies.append(repo.get_movie(int(rank)))

    else:
        index = condition.index('All')
        if index == 0:
            movies = repo.get_movies_by_year(condition[1])
        else:
            movies = repo.get_movies_by_genre(condition[0])

    if movies == []:
        return 'None'

    return movies
def get_10_movie(condition, repo: AbstractRepository):
    movies = []
    #generate 10 random movies
    if condition == 'random':
        random_rank_list = random.sample(
            range(12,
                  repo.get_number_of_movies() + 1), 10)
        for rank in random_rank_list:
            movies.append(repo.get_movie(rank))

    #all genres
    else:
        all_genre_movies = []
        for genre in condition:
            all_genre_movies += [
                movie for movie in repo.get_movies_by_genre(genre.genre_name)
                if movie not in all_genre_movies
            ]
        if len(all_genre_movies) >= 10:
            random_index_list = random.sample(range(len(all_genre_movies)), 10)
        else:  #less than 10 movies among all the genres
            random_index_list = random.sample(range(len(all_genre_movies)),
                                              len(all_genre_movies))
        for index in random_index_list:
            movies.append(all_genre_movies[index])

    if movies is []:
        raise NonExistentMovieException

    return movies
Beispiel #3
0
def get_reviews_for_movie(movie_id, repo: AbstractRepository):
    article = repo.get_movie(movie_id)

    if article is None:
        raise NonExistentMovieException

    return reviews_to_dict(article.comments)
Beispiel #4
0
def get_movie(movie_id: int, repo: AbstractRepository):
    movie = repo.get_movie(movie_id)

    if movie is None:
        raise NonExistentMovieException

    return movie_to_dict(movie)
def get_11_movie(repo: AbstractRepository):
    movies = []

    for rank in range(1, 12):
        movies.append(repo.get_movie(rank))

    if movies is [] or len(movies) != 11:
        raise NonExistentMovieException

    return movies
Beispiel #6
0
def get_reviews_for_movie(movie_rank, repo: AbstractRepository):
    movie = repo.get_movie(movie_rank)
    if movie is None:
        raise NonExistentMovieException
    reviews = repo.get_reviews()
    review_list = []
    for review in reviews:
        if review.movie == movie:
            review_list.append(review)
    return reviews_to_dict(review_list)
Beispiel #7
0
def add_review(rank: int, review_txt: str, rating: int, username: str,
               repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(rank)
    if movie is None:
        raise NonExistentMovieException
    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create review.
    review = Review(movie, review_txt, rating)

    # Update the repository.
    repo.add_review(review)
Beispiel #8
0
def add_review(movie_id: int, review_text: str, username: str,
               repo: AbstractRepository):
    # Check that the movie exists.
    movie = repo.get_movie(movie_id)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    # Create review.
    review = make_review(review_text, user, movie)

    # Update the repository.
    repo.add_review(review)
def add_review(rate: int, rank: int, review_text: str, username: str,
               repo: AbstractRepository):
    # Check that the article exists.
    movie = repo.get_movie(int(rank))
    print(movie)
    if movie is None:
        raise NonExistentMovieException

    user = repo.get_user(username)
    if user is None:
        raise UnknownUserException

    timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    print(timestamp)
    # Create comment.
    review = make_review(review_text, user, movie, timestamp, rate)
    # Update the repository.
    repo.add_review(review)
def get_movie(rank, repo: AbstractRepository):
    return repo.get_movie(int(rank))