def main(): ''' 선택된 6개 영화에 대한 추천 영화 리스트 출력 :return: ''' movielist = request.form.getlist('movieid') ratinglist = request.form.getlist('movierating') data_model = dm() movie_tuple = [] for i, e in enumerate(movielist): movie_tuple.append((e, ratinglist[i])) print(movie_tuple) movie_list = data_model.movie_suggest(movie_tuple) print(list(movie_list)) conn = db_conn.conn() curs = conn.cursor() sql = "SELECT * FROM MOVIE_LIST WHERE MOVIE_ID IN (%s,%s,%s,%s,%s,%s)" curs.execute(sql, (str(movie_list[0]), str(movie_list[1]), str(movie_list[2]), str(movie_list[3]), str(movie_list[4]), str(movie_list[5]))) rows = curs.fetchall() sql_lists = list() for i, e, a in rows: sql_lists.append({'movie_id': i, "title": e, "img_title": a}) print(sql_lists) conn.close() return movie_list
def search(): ''' 검색 한 영화에 대한 surprise알고리즘에 대한 추천 영화 리스트 출력 :param movie_id: :return: ''' movie_title = request.form['movie_title'] conn = db_conn.conn() curs = conn.cursor() like_cur = "%" + movie_title + "%" sql = """SELECT * FROM MOVIE_LIST WHERE TITLE LIKE %s""" curs.execute(sql, (like_cur)) title_ = curs.fetchone()[1] data_model = dm() sug_list = data_model.sim_movie(title_) conn.close() sql = """SELECT * FROM MOVIE_LIST WHERE TITLE IN (""" a = '' list_tuple = [] for i, e in enumerate(sug_list): list_tuple.append(sug_list[i].strip()) if (i == (sug_list.size - 1)): a += '%s )' else: a += '%s ,' sql += a conn = db_conn.conn() curs = conn.cursor() curs.execute(sql, tuple(list_tuple)) rows = curs.fetchall() sql_lists = list() for i, e, a in rows: sql_lists.append({'movie_id': i, "title": e, "img_title": a}) conn.close() return render_template('index.html', sql_list=sql_lists, type="search", result=len(rows))
def rating(): ''' 선택된 6개 영화에 대한 추천 영화 리스트 출력 :return: ''' movielist = request.get_json()['movieid'] ratinglist = request.get_json()['rating'] data_model = dm() movie_tuple = [] movielist = list(movielist) ratinglist = list(ratinglist) for i, e in enumerate(movielist): print(i) movie_tuple.append((e, ratinglist[i])) movie_list = data_model.movie_suggest(movie_tuple) # json으로 리턴 result_json = json.dumps(list(movie_list)) return result_json