-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
69 lines (50 loc) · 1.58 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
from flask import Flask, escape, request, jsonify
from google.cloud import language
from google.cloud.language import enums
from google.cloud.language import types
from subprocess import call
import json
app = Flask(__name__)
@app.route('/')
def hello():
return "here"
@app.route('/create', methods=['GET'])
def load_form(): # get info form
name = str(request.args.get('name')) # find the params
twitter_handle = str(request.args.get('twitter_handle')) # find the params
t = open("handle.txt", "w+")
t.write(twitter_handle)
t.close()
f = open("name.txt", "w+")
f.write(name)
f.close()
call(["python", "mongo_read.py"])
call(["python", "nlp_test.py"])
analysis = open("keys.txt", "r")
local_dict = analysis.read()
analysis.close()
analysis2 = open("keys2.txt", "r")
local_dict2 = analysis2.read()
analysis2.close()
local_dict = json.loads(local_dict)
local_dict2 = json.loads(local_dict2)
keys_List = []
keys_List.append(local_dict)
keys_List.append(local_dict2)
return json.dumps(keys_List)
@app.route("/analyze-text")
def analyze_text():
client = language.LanguageServiceClient()
text = request.args.get("text")
text = text.replace('"', "")
document = types.Document(
content=text,
type=enums.Document.Type.PLAIN_TEXT)
sentiment = client.analyze_sentiment(document=document).document_sentiment
score = sentiment.score
magnitude = sentiment.magnitude
json_return = {
'score': score,
'magnitude': magnitude
}
return jsonify(json_return)