Skip to content

Instantly share code, notes, and snippets.

@crazygmr101
Last active June 25, 2020 10:46
Show Gist options
  • Select an option

  • Save crazygmr101/83ea8a00fee40921dc6de87ec6b3dce1 to your computer and use it in GitHub Desktop.

Select an option

Save crazygmr101/83ea8a00fee40921dc6de87ec6b3dce1 to your computer and use it in GitHub Desktop.
import main
app = main.app
import dotenv
from flask import Flask, send_file
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
import libs.profile
import templating
app = Flask(__name__)
dotenv.load_dotenv(".env")
limiter = Limiter(
app,
key_func=get_remote_address
)
@app.errorhandler(404)
def do_404(e):
return templating.static_page("404"), 404
@app.errorhandler(403)
def do_403(e):
return templating.static_page("403"), 403
@app.errorhandler(500)
def do_500(e):
return templating.static_page("500"), 500
@app.errorhandler(429)
def do_429(e):
return templating.static_page("429"), 429
@app.route("/test/<asset>")
def test(asset):
return templating.static_page(asset)
@app.route("/assets/<asset>")
def get_asset(asset):
return send_file(f"assets/{asset}")
@app.route("/js/<asset>")
def get_js(asset):
return send_file(f"js/{asset}")
@app.route("/")
@app.route("/index")
def index():
return templating.static_page("index", extra_styles="""
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
footer { padding: 10px; padding-top: 8px !important;}
""")
@app.route("/profile/<int:i>")
@limiter.limit("3 per minute")
def profile(i):
return libs.profile.run(i)
@app.route("/commands")
def commands():
with open("templates/commands_init.js") as fp:
js = fp.read()
return templating.static_page("commands", extra_styles="""
body {
display: flex;
min-height: 100vh;
flex-direction: column;
}
main {
flex: 1 0 auto;
}
footer { padding: 10px; padding-top: 8px !important;}"""
, head_inject=f"""
<script type="text/javascript">
{js}
</script>""", onload_inject="Init();")
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment