-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (64 loc) · 2.72 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import logging
import os
import sys
from flask import Flask, request
from Neo4jClient.MovieInsights import MovieInsights
from settings import API_PORT
logging.basicConfig(stream=sys.stdout, level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
log = logging.getLogger(__name__)
app = Flask(__name__)
movie_insignts = MovieInsights()
neo4j_base_client = movie_insignts.neo4j_base_client
@app.route("/query", methods=['POST'])
def query_neo4j():
"""query neo4j interface"""
data = request.get_json()
neo4j_query = data['query']
results = neo4j_base_client.generic_executor(neo4j_query)
jsonified_results = {'neo4j_results': results}
return jsonified_results, 201
@app.route("/genre/movies", methods=['POST'])
def get_genre_data():
"""Returns the provided genre movies"""
data = request.get_json()
genre = data['genre']
genre_movies = movie_insignts.number_of_movies_per_genre(genre)
results = {'{}_movies'.format(genre): genre_movies}
return results, 201
@app.route("/similar/movies", methods=['POST'])
def similar_movies():
"""Returns the provided genre movies"""
data = request.get_json()
movie_title = data['title']
similar_movies_result = movie_insignts.similar_genre_movies(movie_title)
results = {'{}_similar_movies'.format(movie_title): similar_movies_result}
return results, 201
@app.route("/actor/colleagues", methods=['POST'])
def fetch_actor_colleagues():
"""Returns the provided genre movies"""
data = request.get_json()
actor_name = data['actor']
actor_colleagues = movie_insignts.get_actor_colleagues(actor_name)
results = {'{}_colleagues'.format(actor_name): actor_colleagues}
return results, 201
@app.route("/similar/movies/by/genre", methods=['POST'])
def fetch_similar_movies_by_genre():
"""Returns similar by genre movies"""
data = request.get_json()
movie_title = data['title']
similar_movies_by_genre = movie_insignts.similarity_based_on_genre(movie_title)
results = {'{}_similar_movies'.format(movie_title): similar_movies_by_genre}
return results, 201
@app.route("/jaccard/similarity", methods=['POST'])
def similar_movies_jaccard():
"""Returns similar movies using jaccard index"""
data = request.get_json()
movie_title = data['title']
similar_movies_by_genre = movie_insignts.jaccard_similarity(movie_title)
results = {'{}_similar_jaccard'.format(movie_title): similar_movies_by_genre}
return results, 201
if __name__ == '__main__':
log.info("Starting Neo4j Query Execution")
app.secret_key = os.urandom(24)
app.run(host='0.0.0.0', port=API_PORT, debug=True)