diff --git a/src/recommenderapp/app.py b/src/recommenderapp/app.py index aed1c6d38..1405756ce 100644 --- a/src/recommenderapp/app.py +++ b/src/recommenderapp/app.py @@ -2,18 +2,17 @@ Module for routing all calls from the frontend """ -import json -import sys - -from flask import Flask, jsonify, render_template, request +from utils import send_email_to_user, beautify_feedback_data from flask_cors import CORS +from flask import Flask, jsonify, render_template, request from search import Search -from utils import beautify_feedback_data, send_email_to_user - +import sys +import json sys.path.append("../../") -#pylint: disable=wrong-import-position from src.prediction_scripts.item_based import recommend_for_new_user -#pylint: enable=wrong-import-position +# pylint: disable=wrong-import-position +# pylint: enable=wrong-import-position + app = Flask(__name__) app.secret_key = "secret key" @@ -66,7 +65,16 @@ def feedback(): Handles user feedback submission and mails the results. """ data = json.loads(request.data) - user_email = "11rishi.singhal@gmail.com" + return data + + +@app.route("/sendMail", methods=["POST"]) +def sendMail(): + """ + Handles user feedback submission and mails the results. + """ + data = json.loads(request.data) + user_email = data['email'] send_email_to_user(user_email, beautify_feedback_data(data)) return data diff --git a/src/recommenderapp/static/script.js b/src/recommenderapp/static/script.js new file mode 100644 index 000000000..c20e5c9d4 --- /dev/null +++ b/src/recommenderapp/static/script.js @@ -0,0 +1,188 @@ +$(document).ready(function () { + $(function () { + $("#searchBox").autocomplete({ + source: function (request, response) { + $.ajax({ + type: "POST", + url: "http://localhost:5000/search", + dataType: "json", + cache: false, + data: { + q: request.term, + }, + success: function (data) { + //alert(data); + // console.log(data); + response(data); + }, + error: function (jqXHR, textStatus, errorThrown) { + console.log(textStatus + " " + errorThrown); + }, + }); + }, + select: function (event, ui) { + var ulList = $("#selectedMovies"); + // Check if the value already exists in the list + if (ulList.find('li:contains("' + ui.item.value + '")').length > 0) { + $("#searchBox").val(""); + return false; + } + + var li = $("
") + .text(ui.item.value) + .appendTo(ulList); + $("#searchBox").val(""); + return false; + }, + + // changed the min-length for searching movies from 2 to 1 + minLength: 1, + }); + }); + + $("#predict").click(function () { + var movie_list = []; + + $("#selectedMovies li").each(function () { + movie_list.push($(this).text()); + }); + + var movies = { movie_list: movie_list }; + + // Clear the existing recommendations + $("#predictedMovies").empty(); + + // if movies list empty then throw an error box saying select atleast 1 movie!! + if (movie_list.length == 0) { + alert("Select atleast 1 movie!!"); + } + + $.ajax({ + type: "POST", + url: "/predict", + dataType: "json", + contentType: "application/json;charset=UTF-8", + traditional: "true", + cache: false, + data: JSON.stringify(movies), + success: function (response) { + var ulList = $("#predictedMovies"); + var i = 0; + response["recommendations"].forEach((element) => { + var diventry = $(""); + var fieldset = $("", { id: i }).css("border", "0"); + var li = $("").text(element); + var radios = $(` ++ + | ++ + | ++ + | +
- -
-