1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-30 15:04:18 +00:00
royalnet/ohciaovedochestaileggendoilmiostato.py

79 lines
2.1 KiB
Python
Raw Normal View History

2018-10-08 22:51:57 +00:00
from flask import Flask, render_template, request, abort, redirect, url_for
2018-10-07 15:19:42 +00:00
from flask import g as fl_g
import db
import configparser
import datetime
import telegram
from raven.contrib.flask import Sentry
app = Flask(__name__)
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
config = configparser.ConfigParser()
config.read("config.ini")
app.secret_key = config["Flask"]["secret_key"]
telegram_bot = telegram.Bot(config["Telegram"]["bot_token"])
sentry = Sentry(app, dsn=config["Sentry"]["token"])
@app.before_request
def pre_request():
fl_g.event_started, fl_g.event_progress = db.Halloween.puzzle_status()
fl_g.time_left = datetime.datetime.fromtimestamp(1540999800) - datetime.datetime.now()
fl_g.display_on_main_site = (fl_g.time_left < datetime.timedelta(days=7)) or __debug__
fl_g.css = "spoopy.less" if (fl_g.event_started or __debug__) else "nryg.less"
fl_g.rygconf = config
@app.route("/")
def page_owlcaptain():
return render_template("ohciaodinuovo.html")
@app.route("/voiceofevil", methods=["POST"])
def page_voiceofevil():
if request.form.get("solution", "") != "1":
abort(400)
return
2018-10-07 19:26:53 +00:00
if "user_id" not in request.form:
abort(403)
return
2018-10-07 15:19:42 +00:00
db_session = db.Session()
2018-10-07 19:26:53 +00:00
halloween = db_session.query(db.Halloween).filter_by(royal_id=request.form["user_id"]).one_or_none()
2018-10-07 15:19:42 +00:00
if halloween is None:
abort(403)
return
2018-10-07 19:26:53 +00:00
halloween[4] = datetime.datetime.now()
2018-10-07 15:19:42 +00:00
db_session.commit()
return redirect(url_for("page_owlcaptain"))
@app.route("/mansion", methods=["POST"])
def page_mansion():
if request.form.get("solution", "") != "bobooboooboooo":
abort(400)
return
db_session = db.Session()
2018-10-07 19:26:53 +00:00
halloween = db_session.query(db.Halloween).filter_by(royal_id=request.form["user_id"]).one_or_none()
2018-10-07 15:19:42 +00:00
if halloween is None:
abort(403)
return
2018-10-07 19:26:53 +00:00
halloween[6] = datetime.datetime.now()
2018-10-07 15:19:42 +00:00
db_session.commit()
return redirect(url_for("page_owlcaptain"))
@app.route("/whatpumpkin", methods=["POST"])
def page_whatpumpkin():
abort(400)
return
if __name__ == "__main__":
2018-10-07 18:16:10 +00:00
app.run(debug=True, port=1234)