/
app.py~
60 lines (51 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
from flask import Flask, render_template, request
from wtforms import Form, TextAreaField, StringField, validators
from flask_bootstrap import Bootstrap
import indicoio
import json
import pygal
from pygal.style import DarkColorizedStyle
indicoio.config.api_key = 'c938b911dce99664a3af0f077ad2edc6'
app = Flask(__name__)
Bootstrap(app)
class HelloForm(Form):
sayhello = StringField('',[validators.DataRequired()])
@app.route('/')
def index():
form = HelloForm(request.form)
return render_template('index.html', form=form)
'''@app.route('/hello', methods=['POST'])
def hello():
form = HelloForm(request.form)
if request.method == 'POST' and form.validate():
name = request.form['sayhello']
result = indicoio.sentiment(name)
resultEmotion = indicoio.emotion(name);
resultTwitter = indicio.twitter_engagment(name);
resultPersona = indicio.personas(name);
resultPersonality = indicio.personality(name);
#Creating chart of emotions
pie_chart = pygal.Pie(inner_radius=.4, style=DarkColorizedStyle)
pie_chart.title = ''
pie_chart.add('Anger', resultEmotion['anger']*100)
pie_chart.add('Surprise', resultEmotion['surprise']*100)
pie_chart.add('Sadness', resultEmotion['sadness']*100)
pie_chart.add('Fear', resultEmotion['fear']*100)
pie_chart.add('Happiness', resultEmotion['joy']*100)
graph_data = pie_chart.render_data_uri()
return render_template('hello.html', result=result, emotion_graph=graph_data)
#Need to render this somehow...
return render_template('index.html', form=form)'''
@app.route('/dashboard', methods=['POST'])
def pygalexample():
graph = pygal.Line()
graph.title = '% Change Coolness of programming languages over time.'
graph.x_labels = ['2011','2012','2013','2014','2015','2016']
graph.add('Python', [15, 31, 89, 200, 356, 900])
graph.add('Java', [15, 45, 76, 80, 91, 95])
graph.add('C++', [5, 51, 54, 102, 150, 201])
graph.add('All others combined!', [5, 15, 21, 55, 92, 105])
graph_data = graph.render_data_uri()
return render_template("dashboard.html", graph_data = graph_data)
if __name__ == '__main__':
app.run(debug=True)