Example #1
0
def movie(movieID):
    '''Displays detailed information about a specific movie based on
    the movie's imdb id. If tastedive offers recommendations for similar movies,
    then it displays movie recommendations'''
    try:
        dict = movies.movie_info("&i=", movieID)
        recs = []
        try:
            recs = rec_list = movies.movie_rec("&q=movie:",
                                               dict["Title"].replace(" ", "+"))
        except:
            print("Wrong API_KEY")
        # print(recs)
        if (accounts.is_logged_in()):
            alreadyWatched = db.get_movies_watched(session["id"])
            watched = movieID in alreadyWatched
            wishToWatch = db.get_movies_wishlist(session["id"])
            wish = movieID in wishToWatch
            return render_template('movie_info.html',
                                   **dict,
                                   movieID=dict.get('imdbID'),
                                   rec_list=recs,
                                   loggedIn=True,
                                   user=db.get_username(session["id"]),
                                   in_watched=watched,
                                   in_wish=wish)
        else:
            return render_template('movie_info.html',
                                   **dict,
                                   movieID=dict.get('imdbID'),
                                   rec_list=recs,
                                   loggedIn=False)
    except:
        return redirect(url_for('index'))
Example #2
0
def index():
    '''Renders the homepage for users who are both logged in
    and logged out. If user is logged in, displays recommendations
    based on movies added to watched and books added to read.'''
    if (accounts.is_logged_in()):
        watch = db.get_movies_watched(session['id'])
        # print("watched")
        # print(watch)
        data = []
        total = 0
        read = db.get_books_read(session['id'])
        data_books = []
        try:
            for id in watch:
                rec = movies.movie_rec(
                    "&q=movie:",
                    movies.name_from_id(id).replace(" ", "+"))
                data.append(random.choice(rec))
        except:
            print("tastedive not working for movies")
        try:
            for id in read:
                rec_books = books.book_rec(
                    books.name_from_id(id).replace(" ", "+"))
                data_books.append(random.choice(rec_books))
        except:
            print("tastedive not working for books")
        # print(data)
        # print(total)
        return render_template('index.html',
                               loggedIn=True,
                               user=db.get_username(session["id"]),
                               recs_lists=data,
                               recs_lists_books=data_books)
    return render_template('index.html', loggedIn=False)
Example #3
0
def book_search(query):
    '''Displays book results for search query using google books api.
    If no results are found, displays no results message.'''
    if (query == ""):
        return redirect(url_for('index'))
    data = books.google_books_data(query)
    if (accounts.is_logged_in()):
        return render_template('book_search.html',
                               dict=data,
                               query=query,
                               loggedIn=True,
                               user=db.get_username(session["id"]))
    else:
        return render_template('book_search.html',
                               dict=data,
                               query=query,
                               loggedIn=False)
Example #4
0
def watch_list():
    '''Displays a profile page for users where they
    can view the movies they marked as watched'''
    if (accounts.is_logged_in()):
        watch = db.get_movies_watched(session['id'])
        data = []
        try:
            for id in watch:
                data.append(movies.movie_info("&i=", id))
        except:
            print("error")
        return render_template(
            "user_movies.html",
            data=data,
            title="Movies Watched",
            no_results="Looks Like You Haven't Watched Any Movies",
            loggedIn=True,
            user=db.get_username(session["id"]))
    else:
        return redirect(url_for('login'))
Example #5
0
def watch_wishlist():
    '''Displays a profile page for users where they
    can view the movies they wish to watch'''
    if (accounts.is_logged_in()):
        watch = db.get_movies_wishlist(session['id'])
        # print(watch)
        data = []
        try:
            for id in watch:
                data.append(movies.movie_info("&i=", id))
        except:
            print("error")
        # print(data)
        return render_template(
            "user_movies.html",
            data=data,
            title="Want To Watch",
            no_results="Looks Like You Don't Have Any Movies Added",
            loggedIn=True,
            user=db.get_username(session["id"]))
    else:
        return redirect(url_for('login'))
Example #6
0
def book(bookID):
    '''Displays detailed information about a specific book based on
    the book's google book id. If tastedive offers recommendations for similar books,
    then it displays book recommendations'''
    data = books.google_books_data(bookID)
    # print(data)
    try:
        if (accounts.is_logged_in()):
            alreadyRead = db.get_books_read(session["id"])
            read = bookID in alreadyRead
            wishToRead = db.get_books_wishlist(session["id"])
            wish = bookID in wishToRead
            return render_template(
                'book_info.html',
                dict=data,
                rec_list=books.book_rec(
                    books.remove_nonascii(
                        data.get("items")[0]["volumeInfo"]["title"].replace(
                            " ", "+"))),
                bookID=bookID,
                loggedIn=True,
                user=db.get_username(session["id"]),
                in_read=read,
                in_wish=wish)
        else:
            return render_template(
                'book_info.html',
                dict=data,
                rec_list=books.book_rec(
                    books.remove_nonascii(
                        data.get("items")[0]["volumeInfo"]["title"].replace(
                            " ", "+"))),
                bookID=bookID,
                loggedIn=False)
    except:
        return redirect(url_for('index'))
Example #7
0
def read_wishlist():
    '''Displays a profile page for users where they
    can view the books they wish to read'''
    if (accounts.is_logged_in()):
        read = db.get_books_wishlist(session['id'])
        data = []
        try:
            for id in read:
                temp = books.google_books_data(id)
                if "items" in temp:
                    data.append(temp["items"][0])
                else:
                    continue
        except:
            print("error")
        return render_template(
            "user_books.html",
            data=data,
            title="Want To Read",
            no_results="Looks Like You Don't Have Any Books Added",
            loggedIn=True,
            user=db.get_username(session["id"]))
    else:
        return redirect(url_for('login'))
Example #8
0
def movie_search(query):
    '''Displays movie results for search query using OMDB api.
    If no results are found, displays no results message.'''
    # print("inside movie search")
    # print(query)
    try:
        if (query == ""):
            return redirect(url_for('index'))
        list = movies.better_movie_list(
            movies.movie_info("&s=", query).get("Search"))

        if (accounts.is_logged_in()):
            return render_template('movie_search.html',
                                   query=query,
                                   list=list,
                                   loggedIn=True,
                                   user=db.get_username(session["id"]))
        else:
            return render_template('movie_search.html',
                                   query=query,
                                   list=list,
                                   loggedIn=False)
    except:
        return redirect(url_for('index'))