-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.py
More file actions
27 lines (18 loc) · 747 Bytes
/
index.py
File metadata and controls
27 lines (18 loc) · 747 Bytes
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
from flask import Flask, jsonify, request, abort
from flask_cors import CORS
from helpers.fetch_comments import fetch_comments
from models.ytcomment import YTComment
from helpers.get_response import get_response
app = Flask(__name__)
CORS(app)
@app.route('/api/ytVideoId', methods=['POST'])
def process_video_id():
if not request.json or "videoId" not in request.json:
abort(400)
yt_video_id = request.get_json('videoId')['videoId']
comment_data = fetch_comments(yt_video_id)
comments_list = sorted([YTComment(c) for c in comment_data["items"]], key=lambda c: c.sentiment, reverse=True)
response = get_response(comments_list)
return jsonify(response), 201
if __name__ == '__main__':
app.run(debug=True)