Beispiel #1
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    Movie.query.delete()

    with open("seed_data/u.item") as movie_file:
        for row in movie_file:
            row = row.rstrip().split("|")
            movie_id, title, released_at, misc, imdb_url = row[0:5]
            movie_id = int(movie_id)
            title = title[:-7]
            if released_at:
                released_at = datetime.datetime.strptime(
                    released_at, "%d-%b-%Y")
                movie = Movie(movie_id=movie_id,
                              title=title,
                              released_at=released_at,
                              imdb_url=imdb_url)
            else:
                movie = Movie(movie_id=movie_id,
                              title=title,
                              imdb_url=imdb_url)

            db.session.add(movie)

    db.session.commit()
Beispiel #2
0
def add_movie():
    name = request.form.get('name')
    description = request.form.get('description')
    generalRating = request.form.get('generalRating')
    length = request.form.get('length')
    src = request.form.get('src')
    genres = []
    try:
        for genre in Genre.query.all():
            cb = request.form.get('gcb' + str(genre.id))
            if cb is not None:
                genres.append(genre)

        mov = Movie(name=name,
                    description=description,
                    generalRating=generalRating,
                    length=length,
                    isFavorite=False,
                    src=src)

        mov.genres = genres
        db.session.add(mov)
        db.session.commit()
    except Exception:
        flash('')
        return redirect(url_for('movie'))
    return redirect(url_for('movie'))
Beispiel #3
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate movies
    Movie.query.delete()

    # Read u.item file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip().split("|")

        movie = Movie(
            movie_id=row[0],
            title=row[1][:-7],  # Stripping year e.g. _(1995) from title
            released_at=row[2],
            imdb_url=row[4])

        # If released_at is not an empty string, convert to datetime
        if movie.released_at:
            movie.released_at = datetime.strptime(row[2], '%d-%b-%Y')
        else:
            movie.released_at = None

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #4
0
def get_movie_by_id(movie_id):
    """ Return the data for a single movie
    """
    movie = Movie.find_by_id(movie_id)
    if not movie:
        return json_error("couldn't find %s" % movie_id)

    movie = Movie.for_client(movie)
    return json.dumps({ 'movie': movie }), 200
Beispiel #5
0
def predict(movie_id):
    target_movie = Movie.get(movie_id)
    #target_movie = get_movie(movie_id)
    target_ratings = make_target_ratings(movie_id)
    # target_movie_rating = rating
    my_movie_ids = movie_ids(0)

    movies_to_compare = []
    for id in my_movie_ids:
        ratings = make_target_ratings(id)
        movies_to_compare.append(ratings)

    similarities = []

    for ratings in movies_to_compare:
        our_rating = ratings[0] # ratings is not a list, it is a dictionary
        similarity = pearson(target_ratings, ratings)
        tup = (similarity, our_rating)
        similarities.append(tup)

    # (similarity, ranking)

    top_five = sorted(similarities)
    top_five.reverse()
    top_five = top_five[:5]
    num = 0.0
    den = 0.0
    # Use a weighted mean rather than a strict top similarity
    for sim, m in top_five:
        num += (float(sim) * m)
        den += sim

    rating = num/den
    return "%.2f" %(rating)
Beispiel #6
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip().split("|")
        released_str = row[2]
        if released_str:
            released_at = datetime.strptime(released_str, "%d-%b-%Y")
        else:
            released_at = None

        movie = Movie(
                    movie_id=row[0], 
                    title=row[1][:-7],
                    release_at = released_at,
                    imdb_url=row[4]
                    )

        db.session.add(movie)

    db.session.commit()
Beispiel #7
0
def load_movies():
    """Load movies from u.item into database."""


    print("Movies")

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Movie.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip()
        row = row.split("|")
        title, released_at, imdb_url = row[1:4]
        title = title[:-7]


        if released_at:
            released_at = datetime.strptime(released_at, "%d-%b-%Y")
        else:
            released_at = None    

        movie = Movie(title=title, 
                    released_at=released_at,
                    imdb_url=imdb_url)

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #8
0
def load_movies():
    """Load movies from u.item into database."""

    # Delete previous rows in table to avoid duplicates
    Movie.query.delete()

    # Read u.item file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip().split("|")

        movie_id = row[0]
        full_title = row[1].split(" ")
        full_title.pop()
        title = ' '.join(full_title)
        #alternative solution title[:-7]

        released_at = datetime.strptime(row[2], "%d-%b-%Y")

        imdb_url = row[4]

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        # released_at = datetime.strptime(released_at, '%d-%b-%Y')

        #Add movie to session
        db.session.add(movie)

    #Commit session
    db.session.commit()
Beispiel #9
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        row = row.split("|")
        row = row[:5]

        movie_id, title, released_at, video_release, imdb_url = row

        if released_at:
            released_at = datetime.strptime(released_at, "%d-%b-%Y")
        else:
            released_at = None

        title = title[:-7]

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #10
0
def load_movies():
    """Load movies from u.item into database."""
    Movie.query.delete()

    for i, row in enumerate(open("seed_data/u.item")):
        row = row.strip()
        movies_id, title, released_at, empty, imdb_url = row.split("|")[:5]

        format_date = "%d-%b-%Y"

        title = title[:-7]

        movie = Movie(movies_id=movies_id,
                      title=title,
                      released_at=datetime.strptime(released_at, format_date),
                      imdb_url=imdb_url)

        db.session.add(movie)

        # Progress ticker
        if i % 100 == 0:
            print(i)

            db.session.commit()

    db.session.commit()
Beispiel #11
0
def load_movies():
    """Load movies from u.item into database."""
    print "Movies"

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        movie_id, title, release_str, junk, imdb_url = row.split("|")[:5]

        if release_str:
            released_at = datetime.strptime(release_str, "%d-%b-%Y")
        else:
            released_at = None

        title = title.split(" (")[0]

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #12
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")
    Movie.query.delete()

    # Read u.movie and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip()

        movie_id, title, released_str, bleh, imbd_url = row.split("|")[:5]

        if released_str:
            released_at = datetime.strptime(released_str, "%d-%b-%Y")
        else:
            released_at = None

        movie = Movie(movie_id=movie_id,
                      title=title[:-6],
                      released_at=released_at,
                      imbd_url=imbd_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #13
0
def movie_details(movie_id):
    """Show details about a movie."""

    movie = Movie.get_movie_by_id(movie_id)
    release_date = movie.released_at.strftime("%B %d, %Y")

    return render_template('movie_detail.html', movie=movie, release_date=release_date, scores=SCORES)
Beispiel #14
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    Movie.query.delete()

    with open("seed_data/u.item") as movie_file:
        for row in movie_file:

            data = row.rstrip().split("|")

            movie_id = data[0]
            # Slice removes date at end of movie title
            title = data[1][:-7].decode("latin-1")

            if data[2]:
                released_at = datetime.strptime(data[2], '%d-%b-%Y')
            else:
                released_at = None

            imdb_url = data[4]

            movie = Movie(movie_id=movie_id,
                          title=title,
                          released_at=released_at,
                          imdb_url=imdb_url)

            db.session.add(movie)

        db.session.commit()
Beispiel #15
0
def load_movies(movie_filename):
    """Load movies from u.item into database."""

    print("Movies")

    for i, row in enumerate(open(movie_filename)):
        row = row.rstrip()

        # clever -- we can unpack part of the row!
        movie_id, title, released_str, junk, imdb_url = row.split("|")[:5]

        # The date is in the file as daynum-month_abbreviation-year;
        # we need to convert it to an actual datetime object.

        if released_str:
            released_at = datetime.datetime.strptime(released_str, "%d-%b-%Y")
        else:
            released_at = None

        # Remove the (YEAR) from the end of the title.

        title = title[:-7]  # " (YEAR)" == 7

        movie = Movie(title=title, released_at=released_at, imdb_url=imdb_url)

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

        # provide some sense of progress
        if i % 100 == 0:
            print(i)

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #16
0
def load_movies():
    """Load movies from u.item into database."""
    print("Movies")
    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        # row_data = row.split("|")
        movie_id, title, release_str, video_release_date, imdb_url, unknown_genre, action, adventure, animation, childrens, comedy, crime, documentary, drama, fantasy, film_noir, horror, musical, mystery, romance, sci_fi, thriller, war, western = row.split(
            "|")

        stuff = title.split(" ")

        title = stuff[:-1]

        title = " ".join(title)

        # title = title.rstrip()

        if release_str:
            released_at = datetime.strptime(release_str, "%d-%b-%Y")
        else:
            released_at = None

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)
        db.session.add(movie)

    db.session.commit()
Beispiel #17
0
def load_movies():
    """Load movies from u.item into database."""

    # row = row.rstrip("(")
    #datetime.strptime(date_string, "%d-%b-%Y")

    Movie.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip()
        cols = row.split("|")

        (movie_id, title, released_at, _, imdb_url) = cols[:5]

        title = title[:-7]
        released_at = datetime.strptime(released_at, "%d-%b-%Y")

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #18
0
def load_movies():
    """Load movies from u.item into database."""

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        split_row = row.split('|')

        movie_id = split_row[0]
        title = split_row[1]
        released_at = split_row[2]
        imdb_url = split_row[4]

        if released_at:
            released_at = datetime.datetime.strptime(released_at, "%d-%b-%Y")
        else:
            released_at = None

        if title[-1] == ')': # shaving off date in title
            title = title[:-7]

        movie = Movie(movie_id=movie_id, 
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)
        db.session.add(movie)
    
    db.session.commit()
Beispiel #19
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        movie_id, title, released_str, video_release, imdb_url = row.split(
            "|")[0:5]

        # Format movie_id and released_at
        title = title[:-7]
        title = title.decode("latin-1")

        if released_str:
            released_at = datetime.datetime.strptime(released_str, "%d-%b-%Y")
        else:
            released_at = None

        # Assign values to instance attributes
        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #20
0
def load_movies():
    """Load movies from u.item into database."""
    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        items = row.split("|")
        movie_id = items[0]
        title = items[1]
        released_at = items[2]
        imdb_url = items[4]
        #remove year from title
        title = title.split(" (")
        title = title[0]
        #need to formate released at date
        date_format = "%d-%b-%Y"
        released_at = datetime.strptime(released_at, date_format)

        movie = Movie(movie_id=movie_id,
                        title=title,
                        released_at=released_at,
                        imdb_url=imdb_url)
        db.session.add(movie)
    db.session.commit()
Beispiel #21
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        movie_id, title, released_str, space, imdb_url = row.split("|")[0:5]
        title = (title.split(" ")[0:-1])
        title = ' '.join(title)

        if released_str:
            released_at = datetime.datetime.strptime(released_str, "%d-%b-%Y")
        else:
            released_at = None

        # print("DEBUG +++++++++")
        # print(movie_id)
        # print(title)
        # print("END DEBUG +++++++++")
        movie = Movie(movie_id=movie_id,
                    title=title,
                    released_at=released_at,
                    imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()      
Beispiel #22
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        row = row.split("|")

        movie_id = row[0]
        title = row[1]
        released_str = row[2]
        imdb_url = row[4]

        if title:
            title = title[:-7]
            title = title.decode("latin-1")  # decode from latin-1 to unicode

        if released_str:
            released_at = datetime.strptime(released_str, '%d-%b-%Y')
        else:
            released_at = None

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)
        db.session.add(movie)

    db.session.commit()
Beispiel #23
0
def view_movie(id):
    #id = movie.id
    user_id = g.user_id
    if g.user_id:
        movie = Movie.search_movie(id)
        ratings = Rating.search_rating(movie.id, user_id.id)
        beratement = None
        if ratings == None:
            ratings = movie.ratings
            rating_nums = []
            user_rating =None
            for r in ratings:
                rating_nums.append(r.rating)
            avg_rating = float(sum(rating_nums))/len(rating_nums)
            prediction = User.predict_rating(movie.id, user_id.id)
            the_eye = db_session.query(User).filter_by(email="*****@*****.**").one()
            eye_rating = db_session.query(Rating).filter_by(user_id = the_eye.id, movie_id = id).first()
            if not eye_rating:
                eye_rating = User.predict_rating(movie.id, the_eye.id)
                print eye_rating
            else:
                eye_rating = eye_rating.rating
            if prediction:
                difference = abs(eye_rating - prediction)
                messages = [ "I suppose you don't have such bad taste after all.",
                "I regret every decision that I've ever made that has brought me to listen to your opinion.",
                "Words fail me, as your taste in movies has clearly failed you.",
                "That movie is great. For a clown to watch. Idiot.",]
                beratement = messages[int(difference)]
            return render_template("view_movie.html", movie=movie, average=avg_rating, user_rating=user_rating, prediction=prediction, ratings = ratings, beratement=beratement)
        else:
            return render_template("view_movie.html", movie = movie, ratings=ratings)
    return render_template("")
Beispiel #24
0
def load_movies():
    """Load movies from u.item into database."""
    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()

        movie_values = row.split("|")

        movie_id = movie_values[0]
        title = movie_values[1]
        released_at = movie_values[2]
        imdb_url = movie_values[4]

        title = title[0:-7]

        if released_at:
            released_at = datetime.strptime(released_at, "%d-%b-%Y")
        else:
            released_at = None

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #25
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Movie.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip()
        movie_id, title, date, url, *genre = row.split("|")

        # https://stackoverflow.com/questions/6266727/python-cut-off-the-last-word-of-a-sentence
        if title:
        	title = title.rsplit(' ', 1)[0];
        else:
        	title = None

        if date:
        	date = datetime.datetime.strptime(date,"%d-%b-%Y")
        else:
        	date = None

        movie = Movie(movie_id=movie_id,
                    title=title,
                    released_at=date,
                    imdb_url=url)

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #26
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    Movie.query.delete()

    # Read u.user file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip()
        movie_id, title, released_string, video_release_date, imdb_url = row.split(
            "|")[:5]
        # day, month, year = released_string.split("-")

        if released_string:
            released_at = datetime.datetime.strptime(released_string,
                                                     "%d-%b-%Y")
        else:
            released_at = None

        clean_title = re.sub(r"( \(\d{4}\))", "", title)

        movie = Movie(movie_id=movie_id,
                      title=clean_title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #27
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        split_row = row.split("|")
        movie_id = split_row[0]
        full_title = split_row[1]
        title = full_title[:-7]

        release_date_str = split_row[2]
        fmat = "%d-%b-%Y"
        release_date = datetime.strptime(release_date_str, fmat)

        imdb_url = split_row[4]

        # match key with model.py file; released_at

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=release_date,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #28
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip().split("|")

        movie_id = row[0]
        title = row[1]

        # Removes year from movie title
        if title[-1] == ")" and title[-6] == "(" and title[-5:-1].isdigit():
            title = title[:-7]

        if row[2]:
            released_at = datetime.strptime(row[2], '%d-%b-%Y')
        else:
            released_at = None

        imdb_url = row[4]

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #29
0
def load_movies():
    """Load movies from u.item into database."""

    print "Movies"

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip().split("|")
        movie_id = row[0]
        title = row[1][:-7]
        release_date_str = row[2]
        imdb_url = row[4]

        if release_date_str:
            release_date = datetime.strptime(release_date_str, '%d-%b-%Y')
        else:
            release_date = None

        movie = Movie(movie_id=movie_id,
                      title=title,
                      release_at=release_date,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #30
0
def load_movies():
    """Load movies from u.item into database."""

    # Prevent double-adding movies
    Movie.query.delete()

    # Read u.user file and insert data
    f = open("seed_data/u.item")

    for row in f:
        row = row.rstrip()
        movie_id, title, released_at, _, imdb_url = row.split("|")[:5]

        title = title.split("(")[0].rstrip()

        if released_at:
            released_at = datetime.strptime(released_at, "%d-%b-%Y")
        else:
            released_at = None

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        # We need to add to the session or it won't ever be stored
        db.session.add(movie)

    # Close file
    f.close()

    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #31
0
def load_movies():
    """Load movies from u.item into database."""
    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip().split("|")

        (
            movie_id,
            movie_title,
            released_at,
            _,
            imdb_url,
        ) = row[:5]

        movie_title = movie_title[:-7]
        released_at = datetime.strptime(released_at, "%d-%b-%Y")

        movie = Movie(movie_id=movie_id,
                      movie_title=movie_title,
                      released_at=released_at,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()

    print("Movies")
Beispiel #32
0
def load_movies():
    """Load movies from u.item into database."""

    print("Movies")

    Movie.query.delete()

    for movie in open("seed_data/u.item"):
        movie = movie.rstrip()
        movie_info = movie.split("|")
        movie_id = movie_info[0]
        title = movie_info[1]
        title = title.split("(")[0].rstrip()
        release_str = movie_info[2]
        imdb_url = movie_info[4]

        if release_str:
            release_at = datetime.strptime(release_str, '%d-%b-%Y')
        else:
            release_at = None

        movie_data = Movie(movie_id=movie_id,
                           title=title,
                           release_at=release_at,
                           imdb_url=imdb_url)
        db.session.add(movie_data)

    db.session.commit()
Beispiel #33
0
def load_movies():
    """Load movies from u.item into database."""
    print("Movies")

    Movie.query.delete()

    for row in open("seed_data/u.item"):
        row = row.rstrip()
        movie_id, movie_title, release_date, video_release_date, imdb_url,\
        unknown, action, adventure, animation,childrens, comedy, crime,\
        documentary, drama, fantasy, film_noir, horror, musical, mystery,\
        romance, sci_fi, thriller, war, western = row.split("|")

        if release_date:
            release_date = datetime.strptime(release_date, '%d-%b-%Y')
        else:
            release_date = None

        if video_release_date:
            video_release_date = datetime.strptime(video_release_date, '%d-%b-%Y')
        else:
            video_release_date = None

        movie_title = movie_title.rpartition(' (')[0]

        movie = Movie(movie_id=movie_id,
                      movie_title=movie_title,
                      release_date=release_date,
                      video_release_date=video_release_date,
                      imdb_url=imdb_url)

        db.session.add(movie)

    db.session.commit()
Beispiel #34
0
def load_movies():
    """Load movies from u.item into database."""

    print "movies"
    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate movies
    Movie.query.delete()
    # Read u.item file and insert data
    for row in open("seed_data/u.item"):
        row = row.rstrip()
        row = row[:-38]  # removing unneeded info which was genres as 0 and 1s
        movie_id, title, released_str, video_release_date, imdb_url = row.split(
            "|")

        #Formatting release date
        if released_str:
            released_at = datetime.datetime.strptime(released_str, "%d-%b-%Y")
        else:
            released_at = None

        title = title[:-7]  # removing release year

        movie = Movie(movie_id=movie_id,
                      title=title,
                      released_at=released_at,
                      imdb_url=imdb_url)
        # We need to add to the session or it won't ever be stored
        db.session.add(movie)
    # Once we're done, we should commit our work
    db.session.commit()
Beispiel #35
0
def get_ratings(movie_id=None, user_id=None):
    movie = get_movie(movie_id)
    records = Movie.ratings(movie) 
    query = {}
    if movie_id is not None:
        query['movie_id'] = movie_id
    if user_id is not None:
        query['user_id'] = user_id

    return [ rec for rec in records ]
Beispiel #36
0
def movie_details(movie_id):
	movie_id = int(movie_id)
	movie = Movie.get(movie_id)
	title = movie["title"]
	genres = movie["genres"]
	genre = ", ".join(genres)
	imdb = movie["imdb_url"]
	movie_id = movie["_id"]
	rating_records = Rating.get_many(movie_id)
	ratings = [ rec['rating'] for rec in rating_records ]
	avg = float(sum(ratings))/len(ratings)
	return render_template("movie_details.html", title=title, genre=genre, avg=avg, imdb=imdb, movie=movie)
Beispiel #37
0
def post_movie():
    """ Add a movie to the database
    """
    data = json.loads(request.data)
    movie = data.get('movie')

    _id = Movie.create(movie)
    if not _id:
        return json_error("couldn't add movie")
    movie['id'] = _id

    return json.dumps({
        'movie': movie
    }), 200
Beispiel #38
0
def home():
	movie_ids=[]
	ratings=[]
	while len(movie_ids) < 10:
		movie_id = randint(1,1682)
		movie = Movie.get(movie_id)
		movie_ids.append(movie)
		
		movie_id = movie["_id"]
		rating_records = Rating.get_many(movie_id)
		rating = [ rec['rating'] for rec in rating_records ]
		avg = float(sum(rating))/len(rating)
		ratings.append(avg)

	return render_template("potato.html", ratings=ratings, movie_ids=movie_ids)
Beispiel #39
0
def update_rating():
    """Creates/Updates user rating of a specific movie."""

    username = session["username"]
    movie_id = request.form.get("movie_id")
    score = request.form.get("score")
    movie_title = Movie.get_movie_by_id(movie_id).title


    rating_user_id = User.query.filter_by(email=username).first().user_id
    existing_rating = Rating.query.filter(Rating.user_id == rating_user_id, Rating.movie_id == movie_id).first()
    
    if existing_rating:
        existing_rating.score = score
    else:
        new_rating = Rating(movie_id=int(movie_id), user_id=int(rating_user_id), score=int(score))
        db.session.add(new_rating)
    db.session.commit()

    flash("Your rating of " + score + " for " + movie_title + " has successfully been recorded.")

    return redirect("/movies")
Beispiel #40
0
def get_movie():
    """ Return a list of all movies, under the key 'movie'
    """
    movies = Movie.all()
    return json.dumps({ 'movies': movies }), 200
Beispiel #41
0
def average_rating(movie_id):
    movie = Movie.get(movie_id)
    avg = movie.get_average()
    print "%.1f stars"%(avg)
Beispiel #42
0
def get_movie(movie_id):
    return Movie.get(movie_id)
Beispiel #43
0
def average_rating():
	movie_id = request.form['movie_id']
	average = Movie.get_average(str(movie_id))
	return render_template("average_rating.html", average=average)
	pass
Beispiel #44
0
def movie_details():
	movie_id = request.form['movie_id']
	movie = Movie.get(int(movie_id))
	return render_template("movie_details.html", movie=movie)