forked from azk0019/CourseProject
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathflask_main.py
More file actions
30 lines (24 loc) · 680 Bytes
/
flask_main.py
File metadata and controls
30 lines (24 loc) · 680 Bytes
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
from flask import Flask, redirect, url_for, render_template, request
from ranker import ranker
app = Flask(__name__)
@app.route("/", methods=["POST", "GET"])
def home():
request_method = request.method
if request.method == "POST":
user = request.form["nm"]
if user:
return redirect(url_for("results", name=user))
else:
return render_template("main.html")
else:
return render_template("main.html")
@app.route("/results/<string:name>", methods=["GET"])
def results(name):
x = ranker(name)
y = []
for subreddit in x:
if subreddit[0] not in y:
y.append(subreddit[0])
return render_template("results.html", name=y)
if __name__ == "__main__":
app.run()