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.
suchwow/suchwow/app.py

53 lines
1.4 KiB

import json
from os import makedirs
from flask import Flask, request, session
from flask import render_template, flash
from flask_session import Session
from suchwow import config
from suchwow.models import Post, Profile, Comment, Notification, db
from suchwow.routes import auth, comment, post, profile
from suchwow.utils.decorators import login_required
app = Flask(__name__)
app.config.from_envvar("FLASK_SECRETS")
app.secret_key = app.config["SECRET_KEY"]
Session(app)
app.register_blueprint(post.bp)
app.register_blueprint(auth.bp)
@app.route("/")
def index():
itp = 20
page = request.args.get("page", 1)
try:
page = int(page)
except:
flash("Wow, wtf hackerman. Cool it.")
page = 1
posts = Post.select().order_by(Post.timestamp.desc()).paginate(page, itp)
total_pages = round(Post.select().count() / itp)
return render_template("index.html", posts=posts, page=page, total_pages=total_pages)
@app.route("/about")
def about():
return render_template("about.html")
@app.errorhandler(404)
def not_found(error):
return "nothin there, brah"
@app.cli.command("init")
def init():
# create subdirs
for i in ["uploads", "db", "wallet"]:
makedirs(f"{config.DATA_FOLDER}/{i}", exist_ok=True)
# init db
db.create_tables([Post, Profile, Comment, Notification])
if __name__ == "__main__":
app.run()