Skip to content

Commit

Permalink
Merge pull request #15 from adipai/refactor-branch
Browse files Browse the repository at this point in the history
refactor to improve workflow
  • Loading branch information
samarthshetty09 authored Oct 15, 2023
2 parents 7eb4699 + 5518364 commit 552ce2f
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 19 deletions.
Binary file removed Code/recommenderapp/.DS_Store
Binary file not shown.
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
File renamed without changes.
File renamed without changes.
11 changes: 7 additions & 4 deletions Code/recommenderapp/app.py → src/recommenderapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import json
import sys
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
from search import Search
from utils import beautify_feedback_data, send_email_to_user

sys.path.append("../../")
from Code.prediction_scripts.item_based import recommend_for_new_user
#pylint: disable=wrong-import-position
from src.prediction_scripts.item_based import recommend_for_new_user
#pylint: enable=wrong-import-position

app = Flask(__name__)
app.secret_key = "secret key"
Expand Down Expand Up @@ -63,7 +66,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
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
15 changes: 8 additions & 7 deletions Code/recommenderapp/utils.py → src/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import logging
import smtplib
from smtplib import SMTPException
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

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 +54,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 +73,9 @@ def send_email_to_user(recipient_email, categorized_data):
server.sendmail(sender_email, recipient_email, message.as_string())
logging.info("Email sent successfully!")

except Exception as e:
logging.warning("Email could not be sent. Error: %s", str(e))
except SMTPException as e:
# Handle SMTP-related exceptions
logging.error("SMTP error while sending email: %s", str(e))

finally:
server.quit()
8 changes: 4 additions & 4 deletions test/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Test suit for search feature
"""

import sys
import unittest
import warnings
import sys
import os

sys.path.append("../")
from Code.recommenderapp.search import Search
#pylint: disable=wrong-import-position
from src.recommenderapp.search import Search
#pylint: enable=wrong-import-position

warnings.filterwarnings("ignore")

Expand Down
9 changes: 5 additions & 4 deletions test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
Test suite for recommender system
"""

import sys
import unittest
import warnings
import sys

sys.path.append("../")
from Code.prediction_scripts.item_based import recommend_for_new_user
#pylint: disable=wrong-import-position
from src.prediction_scripts.item_based import recommend_for_new_user
#pylint: enable=wrong-import-position

warnings.filterwarnings("ignore")

Expand Down Expand Up @@ -45,7 +46,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 552ce2f

Please sign in to comment.