DEV Community

CodeWizardX1
CodeWizardX1

Posted on

Building MooVeeMatch: A Mood-Based Movie Recommendation Program 🎥✨

Building MooVeeMatch: A Mood-Based Movie Recommendation Program 🎥✨


Introduction

As part of the Codecademy Computer Science curriculum, I recently completed a portfolio project: MooVeeMatch. This program is a mood-based movie recommendation tool that allows users to discover films tailored to how they feel. Whether you're in the mood for something uplifting, adventurous, or mysterious, MooVeeMatch has you covered!

In this blog post, I'll walk you through the inspiration behind the project, the technical details of its implementation, and key lessons I learned during development. If you're learning Python or working through Codecademy's curriculum, this might inspire you to build your own mood-based app!


About MooVeeMatch

MooVeeMatch is a command-line application that takes user input (e.g., their mood) and returns a curated list of movies matching their vibe. The program is powered by a Python dictionary (essentially a hash map) that stores moods as keys and lists of movies as values.

Key Features:

  • Mood-Based Recommendations: Search for movies by mood (e.g., uplifting, dark, funny, etc.).
  • Interactive CLI: A clean and user-friendly interface for browsing movie recommendations.
  • Refactored Codebase: Includes both the original implementation and a cleaner, more modular refactored version.
  • Expandable Database: Easily add more moods and movies to the database.

Technical Overview

Data Structure

The core of MooVeeMatch is a dictionary that maps moods to movie lists. This is an example of a hash map in Python, providing efficient O(1) lookups for moods.

Example:

movies_by_mood = {
    "uplifting": [
        ("The Pursuit of Happyness", 2006, "A touching story about perseverance"),
        ("Soul", 2020, "An inspiring animated story about life's purpose")
    ],
    "dark": [
        ("Se7en", 1995, "A gritty thriller about a serial killer"),
        ("The Dark Knight", 2008, "A darker take on the Batman legend")
    ],
    # More moods...
}
Enter fullscreen mode Exit fullscreen mode

Algorithms

  1. Search Algorithm:

    • The program uses the startswith() method to find moods that match the user’s input.
    • Example: If a user types "upl", the program matches it to "uplifting".
  2. Sorting Algorithm:

    • Movie lists are sorted alphabetically before being displayed using Python’s built-in sorted() function.

Program Workflow

  1. Welcome Message: Users are greeted with a decorative ASCII banner.
  2. Mood Input: The program prompts users to enter the first few letters of their mood.
  3. Mood Matching: The program finds matching moods from the database using startswith() and returns a list of matching options.
  4. Recommendations: Users confirm their mood and receive a list of recommended movies with titles, release years, and loglines.
  5. Repeat or Exit: Users can explore other moods or exit the program.

Key Challenges and Refactoring

Challenge: Nested Logic

The original implementation had deeply nested loops and conditionals, making the code harder to read and maintain.

Solution: Refactoring

I refactored the code to improve modularity by breaking it into smaller, single-responsibility functions. For example:

  • Before: Mood matching and movie display were handled within the main loop.
  • After: Separate functions like find_matching_moods() and display_movies_for_mood() streamlined the code.

Here’s an example of a refactored function:

def find_matching_moods(input_mood_letters):
    """Search for moods matching the input letters."""
    return [
        mood for mood in movies_by_mood.keys()
        if mood.startswith(input_mood_letters)
    ]
Enter fullscreen mode Exit fullscreen mode

This refactoring made the codebase more readable and easier to debug, especially as I expanded the movie database.


Lessons Learned

  1. The Importance of Refactoring:

    Writing modular, clean code saves time in the long run. The refactored version of MooVeeMatch was not only easier to debug but also simpler to extend.

  2. Using Hash Maps Effectively:

    Python dictionaries are powerful for storing and retrieving data efficiently. This project reinforced how to leverage hash maps in real-world scenarios.

  3. Small Iterative Improvements:

    Working in small increments—writing a feature, testing it, and improving it—helped me maintain focus and avoid overwhelm.

  4. CLI Design Matters:

    Even in a terminal-based program, user experience is key. Simple touches like a clean banner and well-structured output make a big difference.


Conclusion

MooVeeMatch was a rewarding project that allowed me to apply what I’ve learned in Codecademy’s Computer Science curriculum to a real-world scenario. From handling user input to managing data efficiently, this project helped solidify my Python skills and taught me the value of clean, modular code.


Check Out MooVeeMatch on GitHub!

You can find the full codebase here: [GitHub Repository Link](#)

Feel free to clone it, try it out, and contribute if you’d like!

Top comments (0)