Skip to content

Commit

Permalink
Added movie genre tags in email notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
rishi2019194 committed Oct 14, 2023
1 parent 7eb4699 commit 4c3a762
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Code/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def feedback():
Handles user feedback submission and mails the results.
"""
data = json.loads(request.data)
user_email = "adipai16@gmail.com"
user_email = "11rishi.singhal@gmail.com"
send_email_to_user(user_email, beautify_feedback_data(data))
return data

Expand Down
54 changes: 27 additions & 27 deletions Code/recommenderapp/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@
This module contains all the constants
"""

EMAIL_HTML_CONTENT = """
<html>
<head></head>
<body>
<h1 style="color: #333333;">Movie Recommendations from PopcornPicks</h1>
<p style="color: #555555;">Dear Movie Enthusiast,</p>
<p style="color: #555555;">We hope you're having a fantastic day!</p>
<div style="padding: 10px; border: 1px solid #cccccc; border-radius: 5px; background-color: #f9f9f9;">
<h2>Your Movie Recommendations:</h2>
<h3>Movies Liked:</h3>
<ul style="color: #555555;">
{}
</ul>
<h3>Movies Disliked:</h3>
<ul style="color: #555555;">
{}
</ul>
<h3>Movies Yet to Watch:</h3>
<ul style="color: #555555;">
{}
</ul>
</div>
<p style="color: #555555;">Enjoy your movie time with PopcornPicks!</p>
<p style="color: #555555;">Best regards,<br>PopcornPicks Team 🍿</p>
</body>
</html>
"""
EMAIL_HTML_CONTENT ="""
<html>
<head></head>
<body>
<h1 style="color: #333333;">Movie Recommendations from PopcornPicks</h1>
<p style="color: #555555;">Dear Movie Enthusiast,</p>
<p style="color: #555555;">We hope you're having a fantastic day!</p>
<div style="padding: 10px; border: 1px solid #cccccc; border-radius: 5px; background-color: #f9f9f9;">
<h2>Your Movie Recommendations:</h2>
<h3>Movies Liked:</h3>
<ul style="color: #555555;">
{}
</ul>
<h3>Movies Disliked:</h3>
<ul style="color: #555555;">
{}
</ul>
<h3>Movies Yet to Watch:</h3>
<ul style="color: #555555;">
{}
</ul>
</div>
<p style="color: #555555;">Enjoy your movie time with PopcornPicks!</p>
<p style="color: #555555;">Best regards,<br>PopcornPicks Team 🍿</p>
</body>
</html>
"""
55 changes: 51 additions & 4 deletions Code/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,42 @@
from email.mime.multipart import MIMEMultipart

import constants as c
import pandas as pd

def create_colored_tags(genres):
"""
Utility function for creating colored tags for movie 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):
"""
Expand Down Expand Up @@ -52,12 +87,24 @@ 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():
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}</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']))
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']))


# Attach the HTML email body
message.attach(MIMEText(html_content, 'html'))
Expand Down

0 comments on commit 4c3a762

Please sign in to comment.