forked from git-ankit/MovieRecommender
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
34 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
from email.mime.multipart import MIMEMultipart | ||
|
||
import pandas as pd | ||
import constants as c | ||
|
||
def create_colored_tags(genres): | ||
""" | ||
|
@@ -83,19 +82,48 @@ def create_movie_genres(movie_genre_df): | |
genres = row[1]['genres'].split('|') | ||
movie_to_genres[movie] = genres | ||
return movie_to_genres | ||
|
||
def send_email_to_user(recipient_email, categorized_data): | ||
""" | ||
Utility function to send movie recommendations to user over email | ||
""" | ||
|
||
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 configuration | ||
smtp_server = 'smtp.gmail.com' | ||
# Port for TLS | ||
smtp_port = 587 | ||
sender_email = '[email protected]' | ||
|
||
# Use an app password since 2-factor authentication is enabled | ||
sender_password = '' | ||
sender_password = 'uxnd shis sazo mstj' | ||
subject = 'Your movie recommendation from PopcornPicks' | ||
|
||
# Create the email message | ||
|
@@ -108,7 +136,7 @@ def send_email_to_user(recipient_email, categorized_data): | |
# Creating movie-genres map | ||
movie_to_genres = create_movie_genres(movie_genre_df) | ||
# Create the email message with HTML content | ||
html_content = c.EMAIL_HTML_CONTENT.format( | ||
html_content = 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']), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
Test suit for search feature | ||
""" | ||
|
||
import sys | ||
import unittest | ||
import warnings | ||
import pandas as pd | ||
sys.path.append("../") | ||
#pylint: disable=wrong-import-position | ||
from src.recommenderapp.utils import create_colored_tags, beautify_feedback_data, create_movie_genres, send_email_to_user | ||
#pylint: enable=wrong-import-position | ||
|
||
warnings.filterwarnings("ignore") | ||
|
||
|
||
class Tests(unittest.TestCase): | ||
""" | ||
Test cases for utility functions | ||
""" | ||
|
||
def test_beautify_feedback_data(self): | ||
""" | ||
Test case 1 | ||
""" | ||
data = {'Movie 1': 'Yet to watch', | ||
'Movie 2': 'Like', 'Movie 3': 'Dislike'} | ||
result = beautify_feedback_data(data) | ||
expected_result = {"Liked": ['Movie 2'], "Disliked": [ | ||
'Movie 3'], "Yet to Watch": ['Movie 1']} | ||
|
||
self.assertTrue(result == expected_result) | ||
|
||
def test_create_colored_tags(self): | ||
""" | ||
Test case 2 | ||
""" | ||
expected_result = '<span style="background-color: #FF1493; color: #FFFFFF; padding: 5px; border-radius: 5px;">Musical</span>' | ||
result = create_colored_tags(['Musical']) | ||
self.assertTrue(result == expected_result) | ||
|
||
def test_create_movie_genres(self): | ||
""" | ||
Test case 3 | ||
""" | ||
expected_result = {'Toy Story (1995)': ['Animation', 'Comedy', 'Family'], 'Jumanji (1995)': [ | ||
'Adventure', 'Fantasy', 'Family']} | ||
movie_genre_df = pd.read_csv('../data/movies.csv').head(n=2) | ||
result = create_movie_genres(movie_genre_df) | ||
self.assertTrue(result == expected_result) | ||
|
||
def test_send_email_to_user(self): | ||
""" | ||
Test case 4 | ||
""" | ||
data = {"Liked": ['Toy Story (1995)'], "Disliked": [ | ||
'Cutthroat Island (1995)'], "Yet to Watch": ['Assassins (1995)']} | ||
with self.assertRaises(Exception): | ||
send_email_to_user("wrong_email", beautify_feedback_data(data)) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |