-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.py
89 lines (73 loc) · 2.67 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
#
# -To be used for locally (localhost) testing the web server/website.
# -Installing the flask package on a virtual environment (instead of system-wide)
# is recommended by Flask devs.
#
# http://flask.pocoo.org/docs/0.12/quickstart/#
#
# -Isaac Park, keonp2
#
from flask import Flask, request, render_template, redirect, url_for, session
from flask_session import Session
from run import display_praw, stats_praw, body_to_graph, get_keyword_dict
import webbrowser
app = Flask(__name__)
app.config['SECRET_KEY'] = 'insert super secret string here'
SESSION_TYPE = 'filesystem'
app.config.from_object(__name__)
Session(app)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'basic-url' in request.form:
name = request.form['basic-url']
info = stats_praw(name)
session['info'] = info
output = display_praw(name)
session['output'] = output
keywords = get_keyword_dict(output)
graph_url = body_to_graph(keywords, name)
session['graph_url'] = graph_url
return redirect(url_for('program', name=name))
else:
return render_template('home.html')
# TODO: Implement subreddit input validity checking AKA Fix blank input error
else:
return render_template('home.html')
@app.route('/docs/<section>')
def docs(section):
if section == "findings":
return render_template("docs_findings.html")
else:
if section == "team":
return render_template("docs_team.html")
else:
if section == "tools":
return render_template("docs_tools.html")
else:
return "This docs page does not exist. Maybe it was a typo? <br><br> -Isaac <br><br><a href='/'>Back to Reddit_Unlocked Home</a>"
# TODO: if I have time, implement html template for page DNE message
@app.route('/program/<name>')
def program(name):
output = session['output']
info = session['info']
graph_url = session['graph_url']
return render_template('program.html', name=name, output=output, info=info, graph_url=graph_url)
@app.route('/examples')
def examples():
return render_template('examples.html')
if __name__ == "__main__":
webbrowser.open_new('http://127.0.0.1:5000')
app.run(debug=False)
# Use url_for method for links in the webpage; url_for generates URL
# based on the argument it is given (name of the function related to a URL.
#
# Example:
#
# @app.route('/user/<name>')
# def hello_user(name):
# if name =='admin':
# return redirect(url_for('hello_admin'))
# else:
# return redirect(url_for('hello_guest',guest = name))
#