-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_interface.py
56 lines (45 loc) · 1.85 KB
/
run_interface.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
import glob
import os
import time
from flask import Flask, render_template, request
import illustrator
import ttweets
import get_charts
app = Flask(import_name=__name__)
@app.route('/')
def home():
description = 'Insira um termo de pesquisa para descobrir o sentimento das pessoas em relação a ele no Twitter.'
return render_template('index.html', title='Twitter Sentimentalizer',
description=description,
readed_tweets=get_charts.readed_tweets(),
good_tweets=get_charts.good_tweets(),
bad_tweets=get_charts.bad_tweets(),
neu_tweets=get_charts.neutral_tweets(),
top_terms=get_charts.top_tweets(),
total_searchs = get_charts.total_searchs())
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/devs')
def devs():
return render_template('devs.html')
@app.route('/results', methods=['POST'])
def result():
term_search = request.form['search']
try:
tweets, pos, neg = ttweets.get_tweets(term_search)
files = glob.glob('./static/images/*')
for f in files:
os.remove(f)
illustrator.draw_wordcloud(neg, 'twitter_mask2.png', False)
illustrator.draw_wordcloud(pos, 'twitter_mask2.png', True)
description = 'Aqui está o que encontramos:'
time.sleep(3)
return render_template('results.html', title='Resultados',
tweets=tweets, description=description,
url1='./static/images/neg_plot.png',
url2='./static/images/pos_plot.png')
except:
return render_template('error.html', term=term_search)
# port = int(os.environ.get('PORT', 33507))
# app.run(debug=True, port=port)