Skip to content

Commit 3ffc762

Browse files
committed
DAY 12 OF 14 PYTHON CHALLENGE
1 parent 40345ee commit 3ffc762

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from flask import Flask, render_template, request
2+
from scrapper import aggregate_subreddits
3+
4+
app = Flask("RedditNews")
5+
6+
subreddits = [
7+
"javascript",
8+
"reactjs",
9+
"reactnative",
10+
"programming",
11+
"css",
12+
"golang",
13+
"flutter",
14+
"rust",
15+
"django"
16+
]
17+
18+
@app.route("/")
19+
def home():
20+
return render_template("home.html", subreddits=subreddits)
21+
22+
23+
@app.route("/read")
24+
def read():
25+
selected = []
26+
for subreddit in subreddits:
27+
if subreddit in request.args:
28+
selected.append(subreddit)
29+
posts = aggregate_subreddits(selected)
30+
posts.sort(key=lambda post: post['votes'], reverse=True)
31+
return render_template("read.html", selected=selected, posts=posts)
32+
33+
app.run(host="0.0.0.0")

0 commit comments

Comments
 (0)