diff --git a/src/recommenderapp/app.py b/src/recommenderapp/app.py index 5d37ac330..aed1c6d38 100644 --- a/src/recommenderapp/app.py +++ b/src/recommenderapp/app.py @@ -66,7 +66,7 @@ def feedback(): Handles user feedback submission and mails the results. """ data = json.loads(request.data) - user_email = "ananyamantravadi@gmail.com" + user_email = "11rishi.singhal@gmail.com" send_email_to_user(user_email, beautify_feedback_data(data)) return data diff --git a/src/recommenderapp/utils.py b/src/recommenderapp/utils.py index 83c04eb3e..9cb70fc33 100644 --- a/src/recommenderapp/utils.py +++ b/src/recommenderapp/utils.py @@ -2,12 +2,45 @@ import logging import smtplib +import pandas as pd from smtplib import SMTPException from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import constants as c +def create_colored_tags(genres): + # Define colors for specific genres + genre_colors = { + 'Musical': '#FF1493', # DeepPink + 'Sci-Fi': '#00CED1', # DarkTurquoise + 'Mystery': '#8A2BE2', # BlueViolet + 'Thriller': '#FF4500', # OrangeRed + 'Horror': '#FF0000', # Red + 'Documentary': '#228B22', # ForestGreen + 'Fantasy': '#FF8C00', # DarkOrange + 'Adventure': '#FFD700', # Gold + 'Children': '#32CD32', # LimeGreen + 'Film-Noir': '#000000', # Black + 'Comedy': '#FFD700', # Gold + 'Crime': '#8B0000', # DarkRed + 'Drama': '#8B008B', # DarkMagenta + 'Western': '#FF6347', # Tomato + 'IMAX': '#7FFFD4', # Aquamarine + 'Action': '#FF4500', # OrangeRed + 'War': '#B22222', # FireBrick + '(no genres listed)': '#A9A9A9', # DarkGray + 'Romance': '#FF69B4', # HotPink + 'Animation': '#20B2AA' # LightSeaGreen + } + tags = [] + for genre in genres: + color = genre_colors.get(genre, '#CCCCCC') # Default color if not found + tag = f'{genre}' + tags.append(tag) + return ' '.join(tags) + def beautify_feedback_data(data): """ Utility function to beautify the feedback json containing predicted movies for sending in email @@ -52,12 +85,29 @@ 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 row in movie_genre_df.iterrows(): + movie = row[1]['title'] + genres = row[1]['genres'].split('|') + movie_to_genres[movie] = genres # Create the email message with HTML content html_content = c.EMAIL_HTML_CONTENT.format( - '\n'.join(f'