-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
26 lines (22 loc) · 1.01 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
from flask import Flask, request, render_template
from machinelearning.mainml import sentiment_analysis
from prawcore.exceptions import NotFound, Forbidden, ResponseException
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == "POST":
subreddit = request.form["subreddit"]
try:
most_positive, most_negative, percentages = sentiment_analysis(subreddit)
except NotFound or Forbidden or ResponseException:
error = "Subreddit does not exist. Please try again."
return render_template('main.html', error=error)
except IndexError:
error = "Please enter a subreddit to analyze."
return render_template('main.html', error=error)
return render_template('main.html',
positive=most_positive,
negative=most_negative,
percentages=percentages)
else:
return render_template('main.html')