From 57a6046ff1f4ccb7958ed51ec3720802680bc744 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Sat, 14 Oct 2023 10:53:17 -0400 Subject: [PATCH] refactor to improve workflow --- Code/recommenderapp/app.py | 10 +++++----- Code/recommenderapp/utils.py | 16 ++++++++++------ setup.py | 11 +++++++++++ test/test_search.py | 7 +++---- test/tests.py | 7 +++---- 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/Code/recommenderapp/app.py b/Code/recommenderapp/app.py index dc94f4631..b1ee67ef9 100644 --- a/Code/recommenderapp/app.py +++ b/Code/recommenderapp/app.py @@ -2,16 +2,16 @@ Module for routing all calls from the frontend """ -import json import sys +sys.path.append("../../") +from Code.prediction_scripts.item_based import recommend_for_new_user + +import json from search import Search from flask import Flask, jsonify, render_template, request from flask_cors import CORS 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" @@ -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 = "ananyamantravadi@gmail.com" send_email_to_user(user_email, beautify_feedback_data(data)) return data diff --git a/Code/recommenderapp/utils.py b/Code/recommenderapp/utils.py index 7858f4244..a5b789c4c 100644 --- a/Code/recommenderapp/utils.py +++ b/Code/recommenderapp/utils.py @@ -7,7 +7,6 @@ import constants as c - def beautify_feedback_data(data): """ Utility function to beautify the feedback json containing predicted movies for sending in email @@ -54,10 +53,10 @@ def send_email_to_user(recipient_email, categorized_data): message['Subject'] = subject # Create the email message with HTML content - html_content = c.EMAIL_HTML_CONTENT.format('\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Liked']), - '\n'.join( - f'
  • {movie}
  • ' for movie in categorized_data['Disliked']), - '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Yet to Watch'])) + html_content = c.EMAIL_HTML_CONTENT.format( + '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Liked']), + '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Disliked']), + '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Yet to Watch'])) # Attach the HTML email body message.attach(MIMEText(html_content, 'html')) @@ -73,8 +72,13 @@ def send_email_to_user(recipient_email, categorized_data): server.sendmail(sender_email, recipient_email, message.as_string()) logging.info("Email sent successfully!") + except SMTPException as e: + # Handle SMTP-related exceptions + logging.error("SMTP error while sending email: %s", str(e)) + except Exception as e: - logging.warning("Email could not be sent. Error: %s", str(e)) + # Handle other exceptions + logging.error("An unexpected error occurred while sending email: %s", str(e)) finally: server.quit() diff --git a/setup.py b/setup.py index d4e434253..45d04eaf8 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,14 @@ +""" +Movie Recommender Setup Script + +This script is used to package and distribute the Movie Recommender project. +It contains information about the project, including its name, version, authors, +description, and other relevant details, to facilitate distribution and installation. + +For more information about the Movie Recommender project, visit: +https://github.com/git-ankit/MovieRecommender +""" + import setuptools with open("README.md", "r", encoding="utf8") as fh: diff --git a/test/test_search.py b/test/test_search.py index e5c8cb788..56c945904 100644 --- a/test/test_search.py +++ b/test/test_search.py @@ -2,14 +2,13 @@ Test suit for search feature """ -import unittest -import warnings import sys -import os - sys.path.append("../") from Code.recommenderapp.search import Search +import unittest +import warnings + warnings.filterwarnings("ignore") class Tests(unittest.TestCase): diff --git a/test/tests.py b/test/tests.py index 82d3fc552..05e15a3a3 100644 --- a/test/tests.py +++ b/test/tests.py @@ -2,13 +2,12 @@ Test suite for recommender system """ -import unittest -import warnings import sys - sys.path.append("../") from Code.prediction_scripts.item_based import recommend_for_new_user +import unittest +import warnings warnings.filterwarnings("ignore") @@ -45,7 +44,7 @@ def test_horror_with_cartoon(self): {"title": "Strangers, The (2008)", "rating": 5.0}, ] recommendations = recommend_for_new_user(ts) - self.assertTrue(("Toy Story (1995)" in recommendations) == False) + self.assertTrue(("Toy Story (1995)" in recommendations) is False) def test_iron_man(self): """