Movie Voter Web Application

Project Description

This was my final project for Harvard's CS50x: Introduction to Computer Science. It's a web-based application that helps groups decide what movies to watch together. The video above demonstrates the intended usage of the site.

Technical Details

Languages & Technologies Used

Code Snippet

This function is part of the Movie Voter application's ranking logic. It demonstrates the use of Flask for routing and SQLite for database management. See the full project on GitHub.

  @app.route("/rankings")
  @login_required
  def rankings():
      """
      Display ranked movies for all groups the user is a member of.
      Each group's movie rankings are based on the number of votes each movie received.
  
      Returns:
          Rendered HTML template displaying movie rankings for each group.
      """
  
      # Query to fetch all the groups the current user is a member of
      groups = db.execute("SELECT groupname, id FROM groups WHERE id IN (SELECT group_id FROM members WHERE user_id = ?)", session["user_id"])
  
      # Iterate over each group to retrieve its movie rankings
      for group in groups:
          # Query to fetch the movies and their vote counts, ordered by the number of votes (frequency)
          movies = db.execute("SELECT movies.title, movies.year, COUNT(watch_list.movie_id) as frequency \
                              FROM movies INNER JOIN watch_list ON movies.id=watch_list.movie_id \
                              WHERE watch_list.group_id = ? \
                              GROUP BY watch_list.group_id, watch_list.movie_id \
                              ORDER BY COUNT(watch_list.movie_id) DESC;", group['id'])
  
          # Attach the list of ranked movies to the group
          group['movies'] = movies
  
      # Render the rankings.html template, passing the list of groups and their ranked movies
      return render_template("rankings.html", groups=groups)