-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
57 lines (44 loc) · 1.62 KB
/
Copy pathapi.py
File metadata and controls
57 lines (44 loc) · 1.62 KB
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
import json
from flask import Flask, request, Response, send_file
from yc import *
from word_count import *
from topic_modelling import *
from sentiment_analysis import *
app = Flask(__name__)
@app.route('/comments/wc/<video_id>', methods=['GET'])
def get_wc_api(video_id):
"""
"""
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
comments = []
video_comment_threads = get_comment_threads(youtube, video_id, comments)
for thread in video_comment_threads:
get_comments(youtube, thread["id"], comments)
return get_word_count(comments)
@app.route('/comments/tm/<video_id>', methods=['GET'], )
def get_tm_api(video_id):
"""
"""
ngram = int(request.args.get('ngram', default=1))
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
comments = []
video_comment_threads = get_comment_threads(youtube, video_id, comments)
for thread in video_comment_threads:
get_comments(youtube, thread["id"], comments)
return get_topics_ngram(comments, ngram=ngram)
@app.route('/comments/sa/<video_id>', methods=['GET'], )
def get_sa_api(video_id):
"""
"""
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
comments = []
video_comment_threads = get_comment_threads(youtube, video_id, comments)
for thread in video_comment_threads:
get_comments(youtube, thread["id"], comments)
return get_sentiment_analysis(comments)
if __name__ == '__main__':
app.run(
host="0.0.0.0",
port=int("8087"),
debug=True
)