from bottle import request, response, abort, static_file from kddit import app from urllib.parse import urlparse from kddit import settings from kddit.utils import req, success, ydl, req_url from kddit import html from kddit.utils import verify_subreddit_option, verify_user_option from kddit.utils import get_subreddit_url, get_subreddit from kddit.utils import nsfw_mode, get_query def subreddit_content(data, subreddit, option, time, safe): content = (html.subreddit_menu(option, subreddit)) if option in settings.EXPANDED_OPTIONS: content += (html.subreddit_sort_menu(subreddit, option or settings.DEFAULT_OPTION, time)) content += (html.mixed_content(data, safe) or html.nothing,) content += html.subreddit_nav(data, subreddit, option, time) return content def search_content(data, subreddit, sort, time, query): content = html.search_sort_menu(subreddit, query) content += html.search_time_menu(subreddit, query ) content += html.mixed_content(data, True) or html.nothing content += html.search_nav(data, subreddit, query) return content def domain_content(data, domain, option, time): content = html.domain_menu(option, domain) if option in settings.EXPANDED_OPTIONS: content += html.domain_sort_menu(domain, option or settings.DEFAULT_OPTION, time) content += html.mixed_content(data, True) or html.nothing content += html.domain_nav(data, domain, option, time) return content def user_content(data, user, option, sort): content = html.user_menu(option, user) content += html.user_sort_menu(option, sort, user) content += (html.mixed_content(data, True, True),) content += html.user_nav(data, user, option, sort) return content def multi_content(data, user, multi, option, sort): content = html.multi_menu(option, user, multi) content += html.multi_sort_menu(user, multi, option, sort) content += (html.mixed_content(data, True),) content += html.multi_nav(data, user, multi, option, sort) return content @app.route("/search", "GET") @app.route("/r//search", "GET") def search_page(subreddit=None): url = f'{get_subreddit_url()}/search/.json' query = dict(request.query) r = req(url, query) if success(r): data = r.json() time = query.get("t") sort = query.get("sort") q = query.get("q") or "" title = f"search results - {q}" header = html.page_header(subreddit=subreddit) content = search_content(data, subreddit, sort, time, query) return html.page(title, header, content).render() else: return abort(r.status_code) @app.route("/u//m/", "GET") @app.route("/user//m/", "GET") @app.route("/u//m//