Skip to content

Commit

Permalink
parse json and beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
ananya173147 committed Oct 8, 2023
1 parent 061d42d commit 9c7a428
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Code/recommenderapp/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from search import Search
from Code.prediction_scripts.item_based import recommendForNewUser
from flask import Flask, jsonify, render_template, request
from flask_cors import CORS, cross_origin
import json
import sys
from utils import *
sys.path.append("../../")
from Code.prediction_scripts.item_based import recommendForNewUser
from search import Search

app = Flask(__name__)
app.secret_key = "secret key"
Expand Down Expand Up @@ -47,8 +47,8 @@ def search():
@app.route("/feedback", methods=["POST"])
def feedback():
data = json.loads(request.data)
user_email = "adipai16@gmail.com"
send_email_to_user(user_email, str(data))
user_email = "ananyamantravadi@gmail.com"
send_email_to_user(user_email, str(beautify_feedback_data(data)))
return data


Expand Down
23 changes: 21 additions & 2 deletions Code/recommenderapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,26 @@ def beautify_feedback_data(data):
"""
Utility function to beautify the feedback json containing predicted movies for sending in email
"""
pass
# Create empty lists for each category
yet_to_watch = []
like = []
dislike = []

# Iterate through the data and categorize movies
for movie, status in data.items():
if status == 'Yet to watch':
yet_to_watch.append(movie)
elif status == 'Like':
like.append(movie)
elif status == 'Dislike':
dislike.append(movie)

# Create a plain text string for the categorized data
categorized_data_str = "Movies Yet to Watch:\n" + "\n".join(yet_to_watch) + "\n\n"
categorized_data_str += "Movies Liked:\n" + "\n".join(like) + "\n\n"
categorized_data_str += "Movies Disliked:\n" + "\n".join(dislike)

return categorized_data_str

def send_email_to_user(recipient_email, message_body):
"""
Expand All @@ -21,7 +40,7 @@ def send_email_to_user(recipient_email, message_body):
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
Expand Down

0 comments on commit 9c7a428

Please sign in to comment.