Book Recommendation Software

I just finished learning Codecademy's Computer Science: Data Structures & Algorithm module. To end the module, I had to create a second portfolio project - a recommendation software.

The requirements were:

  1. Store data in a data structure
  2. Use an algorithm to sort or search for data within a data structure
  3. Use Git version control
  4. Use the command line and file navigation
  5. Write a technical blog post on the project

I considered what types of recommendation software were out there, and I decided to keep my scope relatively narrow. I work at the dining table, so I thought it would be easy and fun to simply turn around and input a few random books on my bookshelf and make book recommendations to people (i.e. my partner).

I love to read, and I recently had to cull some beloved books when my partner and I moved from coast to coast. So the books currently on my bookshelf are really /la crème de la crème/.

Nevertheless, I gritted my teeth and /ranked/ my books anyway in a rating system of 1-5. I took a small, assorted sample of my books and imported a csv to Visual Studio Code. The individual books ended up being stored as a dictionary within a list.
Each book had the following key:value pairs:
'category'
'category_lower'
'rating'
'author'
'author_lower'
'title'
'title_lower'

I started with a simple sorting algorithm - quicksort. And I tested it by sorting my books alphabetically by author first name and by title. Then I sorted by rating.
Next, I thought, well let's really prove I know how to sort. So I made a bubblesort function, and used that to sort the categories. I knew I would need a list of categories for the actual program, so I removed the duplicates and saved a clean list of categories into a new list variable.
So far, things seemed to be working fine, so I shifted my focus to the actual terminal program.

I thought about how I wanted my books to be searched - by title? by author? by category?
I settled on category because that seemed the most straightforward way to very broadly look for books. When I go into a bookstore, I usually zoom into the SciFi & Fantasy section and browse for whatever looks interesting (purely based on the cover art).

Next, I fiddled around with the user inputs and the possible inputs someone might put in - whether they are following direction or not. After figuring out the conditionals and making the search loopable (so you can find books and then keep looking for books of a different category), I felt like I was ready to get into the "reveal" aspect.

Now, how to grab books that matched the user's inputted category? And how to organize the resulting list based on my top favorite?

First, I made a helper function to match the user input's category with my list of categories. Depending on the match (y/n) and the number of matches (1 or more), the user input loop will eventually narrow down to one category. Phew.

Then, it was a matter of matching the books' category key with the user input's category. If it matched, the book would be appended to a new list.
I decided to print out my top rated book separately from the rest of the list. So people can see all the books in the category with the first one being my favorite, main recommendation.

Voila - I was done. Books for days!!! Happy reading!

Take a look and let me know how the code can be improved:
https://github.com/pwong09/Portfolio-Project-2

17