-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.py
More file actions
45 lines (35 loc) · 1.21 KB
/
application.py
File metadata and controls
45 lines (35 loc) · 1.21 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
from flask import Flask, redirect, render_template, request, url_for
import os
import sys
import helpers
from analyzer import Analyzer
positives = os.path.join(sys.path[0], "positive-words.txt")
negatives = os.path.join(sys.path[0], "negative-words.txt")
analyzer = Analyzer(positives, negatives)
app = Flask(__name__)
port = int(os.environ.get('PORT', 5000))
@app.route("/")
def index():
return render_template("index.html")
@app.route("/search")
def search():
# validate screen_name
screen_name = request.args.get("screen_name", "")
if not screen_name:
return redirect(url_for("index"))
# get screen_name's tweets
tweets = helpers.get_user_timeline(screen_name)
positive, negative, neutral = 0.0, 0.0, 100.0
for i in range(len(tweets)):
tally = analyzer.analyze(tweets[i])
if tally > 0.0:
positive = positive + 1.0
neutral = neutral - 1.0
elif tally < 0.0:
negative = negative + 1.0
neutral = neutral - 1.0
# generate chart
chart = helpers.chart(positive, negative, neutral)
# render results
return render_template("search.html", chart=chart, screen_name=screen_name)
app.run(host='0.0.0.0', port=port)