-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
78 lines (74 loc) · 2.06 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
70
71
72
73
74
75
76
77
78
import os,binascii
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash, Blueprint
from flask import send_from_directory
import datetime, chartkick
import json
from pprint import pprint
import logging
from loklak import Loklak
from collections import Counter
app = Flask(__name__)
ck = Blueprint('ck_page', __name__, static_folder=chartkick.js(), static_url_path='/static')
app.register_blueprint(ck, url_prefix='/ck')
app.jinja_env.add_extension("chartkick.ext.charts")
@app.route('/visualize', methods=['POST'])
def visualize():
q = request.form['q']
l = Loklak()
data = l.search(q)
statuses = data['statuses']
if(len(statuses) == 0):
return render_template('404.html')
emotions = []
languages = []
countries = []
for status in statuses:
try:
emotion = status['classifier_emotion']
language = status['classifier_language']
place = status['place_country']
emotions.append(emotion)
languages.append(language)
countries.append(place)
except:
pass
pprint(emotions)
pprint(languages)
pprint(countries)
try:
languageDict = dict(list(Counter(languages).items()))
pprint(languageDict)
except:
pass
try:
emotionDict = dict(list(Counter(emotions).items()))
pprint(emotionDict)
except:
pass
try:
countryDict = dict(list(Counter(countries).items()))
pprint(countryDict)
except:
pass
languageInfo = {}
emotionInfo = {}
countryInfo = {}
for key, value in languageDict.iteritems():
languageInfo[str(key)] = value
for key, value in emotionDict.iteritems():
emotionInfo[str(key)] = value
for key, value in countryDict.iteritems():
countryInfo[str(key)] = value
return render_template('result.html', q=q, languages=languageInfo, emotions=emotionInfo, country=countryInfo, statuses=statuses)
@app.route('/')
def home():
return render_template('index.html')
@app.route('/about')
def about():
return render_template('loklak.html')
if __name__ == '__main__':
app.debug = True
app.secret_key=os.urandom(24)
# app.permanent_session_lifetime = datetime.timedelta(seconds=200)
app.run()