-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (35 loc) · 1023 Bytes
/
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
from flask import Flask,jsonify
from flask import request
#from tweeter_api.sentiments import Sentiment
from tweeter_api.google_cloud_nlp import Sentiment
from flask_cors import CORS
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= 'static/apikey.json'
app = Flask(__name__)
CORS(app)
@app.route('/')
def index():
return 'tweet-meter'
@app.route('/search/',methods=['GET', 'POST'])
def search():
sentiment = Sentiment(10)
query = ''
if request.method == 'GET': query = request.args.get('query','')
if request.method == 'POST':query = request.get_json()['query']
if query.startswith("https://"):
res = sentiment.replies_analysis(tweet_url=query)
return jsonify(res)
elif query != '':
res = sentiment.tweets_analysis(query=query)
return jsonify(res)
return jsonify({'negative':0,'positive':0,'neutral':0})
@app.errorhandler(500)
def server_error(error):
return 500
@app.errorhandler(404)
def page_not_found(error):
return 404
'''
if __name__=='__main__':
app.run(debug=True, port=5000)
'''