Skip to content

Commit

Permalink
Added movie genre tags in email notifier and refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi2019194 committed Oct 15, 2023
1 parent 4c3a762 commit 5d1980d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Code/recommenderapp/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Module for routing all calls from the frontend
"""

from Code.prediction_scripts.item_based import recommend_for_new_user
import json
import sys
from search import Search
Expand All @@ -10,7 +10,7 @@
from utils import send_email_to_user, beautify_feedback_data

sys.path.append("../../")
from Code.prediction_scripts.item_based import recommend_for_new_user


app = Flask(__name__)
app.secret_key = "secret key"
Expand Down
18 changes: 10 additions & 8 deletions Code/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def create_colored_tags(genres):
}
tags = []
for genre in genres:
color = genre_colors.get(genre, '#CCCCCC') # Default color if not found
tag = f'<span style="background-color: {color}; color: #FFFFFF; padding: 5px; border-radius: 5px;">{genre}</span>'
tags.append(tag)
color = genre_colors.get(genre, '#CCCCCC') # Default color if not found
tag = f'<span style="background-color: {color}; color: #FFFFFF; padding: 5px; border-radius: 5px;">{genre}</span>'
tags.append(tag)

return ' '.join(tags)

Expand Down Expand Up @@ -87,23 +87,25 @@ def send_email_to_user(recipient_email, categorized_data):
message['From'] = sender_email
message['To'] = recipient_email
message['Subject'] = subject

# Load the CSV file into a DataFrame
movie_genre_df = pd.read_csv('../../data/movies.csv')

# Create a dictionary to map movies to their genres
movie_to_genres = {}

for index, row in movie_genre_df.iterrows():
for row in movie_genre_df.rows():
movie = row['title']
genres = row['genres'].split('|')
movie_to_genres[movie] = genres

# Create the email message with HTML content
html_content = c.EMAIL_HTML_CONTENT.format(
'\n'.join(f'<li>{movie} {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' for movie in categorized_data['Liked']),
'\n'.join(f'<li>{movie} {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' for movie in categorized_data['Disliked']),
'\n'.join(f'<li>{movie} {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' for movie in categorized_data['Yet to Watch']))
'\n'.join(f'<li>{movie} {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' \
for movie in categorized_data['Liked']),
'\n'.join(f'<li>{movie} {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' \
for movie in categorized_data['Disliked']),
'\n'.join(f'<li>{movie} {create_colored_tags(movie_to_genres.get(movie, ["Unknown Genre"]))}</li><br>' \
for movie in categorized_data['Yet to Watch']))


# Attach the HTML email body
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Setup.py file for the code
"""
import setuptools

with open("README.md", "r", encoding="utf8") as fh:
Expand Down
2 changes: 1 addition & 1 deletion test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
Test suite for recommender system
"""

from Code.prediction_scripts.item_based import recommend_for_new_user
import unittest
import warnings
import sys

sys.path.append("../")
from Code.prediction_scripts.item_based import recommend_for_new_user

warnings.filterwarnings("ignore")

Expand Down

0 comments on commit 5d1980d

Please sign in to comment.