-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphInt.py
More file actions
executable file
·58 lines (46 loc) · 1.41 KB
/
Copy pathGraphInt.py
File metadata and controls
executable file
·58 lines (46 loc) · 1.41 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
58
from bs4 import BeautifulSoup
from flask import Flask, render_template, request, redirect, url_for
from flask import jsonify
import json
import plot_data
import get_news
import db_op
from pymongo import MongoClient
import config
import get_sentiment
import pickle
# Flask App
app = Flask(__name__, static_url_path='/static')
def load_obj(name):
with open('./obj/' + name + '.pkl', 'rb') as f:
return pickle.load(f)
ner_dict = load_obj('tweet_10000')
ner_id = load_obj('tweet_id_10000')
d = dict(zip(range(0,len(ner_id.keys())),sorted(list(ner_id.keys()))))
print d
result = d
@app.route("/")
def home():
return render_template("index.html", result=result)
@app.route('/graph/', methods=['GET', 'POST'])
def graph():
# req = request.args.get('ner')
# print req
req = json.loads(request.form.to_dict().keys()[0])['ner'].encode('utf-8')
print req
# print request.args.get('ner')
# print len(ner_id['trump'])
time = db_op.get_time(map(int, ner_id[req]))
print time
# print len(time)
plot_data.plot_time(time)
log, lat = db_op.get_coord(map(int, ner_id[req]))
# print log, lat
plot_data.plot_loc(log, lat)
headline = get_news.getNews([req])
print headline
h_s, t_s = get_sentiment.getSentiment(headline, {req: ner_dict[req]})
plot_data.plotSentiment(h_s, t_s)
return str(0)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5003)