bareddit will no longer be maintained by me (metalune) because gophereddit exists https://bareddit.metalune.xyz
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 

34 lines
1.2 KiB

from quart import Quart, request, render_template
from reddit_scraper.reddit_scraper import RedditScraper
from reddit_scraper.models.post_type import PostType
from reddit_scraper.models.sorting_type import SortingType
app = Quart(__name__)
@app.route('/', methods=["GET", "POST"])
async def main():
return await render_template('index.html')
@app.route("/r/<string:subreddit>/", defaults={'sortby': 'hot', 'page': 1})
@app.route("/r/<string:subreddit>/<string:sortby>/<int:page>")
async def load_subreddit(subreddit, sortby, page):
sortingtype = SortingType.HOT
if sortby == "new":
sortingtype = SortingType.NEW
elif sortby == "top":
sortingtype = SortingType.TOP
posts = RedditScraper.get_posts(subreddit, max_count=10 * page, sorting_type=sortingtype)
posts = posts[10 * (page - 1):]
return await render_template('subreddit.html', posts=posts, subreddit=subreddit, sortby=sortby, page=page)
@app.route('/comments/<string:post_id>/')
async def load_post(post_id):
post = RedditScraper.get_post(post_id, comments_min_score=250)
return await render_template('post.html', post=post)
if __name__ == "__main__":
app.run()