Skip to content

Commit

Permalink
Added genre tags in the email notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi2019194 committed Oct 15, 2023
1 parent dd98873 commit 25f665a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 53 additions & 3 deletions src/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<span style="background-color: {color}; color: #FFFFFF; \
padding: 5px; border-radius: 5px;">{genre}</span>'
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
Expand Down Expand Up @@ -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'<li>{movie}</li>' for movie in categorized_data['Liked']),
'\n'.join(f'<li>{movie}</li>' for movie in categorized_data['Disliked']),
'\n'.join(f'<li>{movie}</li>' 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
message.attach(MIMEText(html_content, 'html'))
Expand Down

0 comments on commit 25f665a

Please sign in to comment.