Skip to content

Commit

Permalink
refactor to improve workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ananya173147 committed Oct 14, 2023
1 parent 7eb4699 commit 57a6046
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Code/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down 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 = "ananyamantravadi@gmail.com"
send_email_to_user(user_email, beautify_feedback_data(data))
return data

Expand Down
16 changes: 10 additions & 6 deletions Code/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'<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}</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']))

# Attach the HTML email body
message.attach(MIMEText(html_content, 'html'))
Expand All @@ -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()
11 changes: 11 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
7 changes: 3 additions & 4 deletions test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 3 additions & 4 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 57a6046

Please sign in to comment.