From 9c7a42868e9cc1c9ac6a6f78f241f26169dd0367 Mon Sep 17 00:00:00 2001 From: ananya173147 Date: Sun, 8 Oct 2023 14:14:55 -0400 Subject: [PATCH] parse json and beautify --- Code/recommenderapp/app.py | 8 ++++---- Code/recommenderapp/utils.py | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Code/recommenderapp/app.py b/Code/recommenderapp/app.py index 145e7eb0a..c32ba7c33 100644 --- a/Code/recommenderapp/app.py +++ b/Code/recommenderapp/app.py @@ -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" @@ -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 diff --git a/Code/recommenderapp/utils.py b/Code/recommenderapp/utils.py index 508f789a9..1bcefc68f 100644 --- a/Code/recommenderapp/utils.py +++ b/Code/recommenderapp/utils.py @@ -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): """ @@ -21,7 +40,7 @@ def send_email_to_user(recipient_email, message_body): sender_email = 'popcornpicks504@gmail.com' # 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