quiz-the-word/main.py

59 lines
1.6 KiB
Python
Raw Normal View History

2021-03-07 17:13:11 -08:00
import os
2021-03-18 20:08:19 -07:00
from flask import Flask, render_template, request, jsonify
from flask_security import Security
2021-03-06 14:29:44 -08:00
import database
from admin import admin
2021-03-06 14:29:44 -08:00
app = Flask(__name__)
app.register_blueprint(admin.Admin)
2021-03-07 17:13:11 -08:00
environment_configuration = os.environ['CONFIGURATION_SETUP']
app.config.from_object(environment_configuration)
2021-03-06 14:29:44 -08:00
@app.route("/")
def index():
2021-03-18 20:08:19 -07:00
return multiple_choice_category()
@app.route("/category/hidden_answer")
def hidden_answer_category():
easy = database.get_random_hidden_answer(1)
medium = database.get_random_hidden_answer(2)
hard = database.get_random_hidden_answer(3)
2021-03-06 14:29:44 -08:00
return render_template(
"hidden_answer.html",
2021-03-18 20:08:19 -07:00
title="Hidden Answer",
2021-03-06 14:29:44 -08:00
easy=easy,
medium=medium,
hard=hard,
)
2021-03-18 20:08:19 -07:00
@app.route("/category/multiple_choice")
def multiple_choice_category():
easy = database.get_random_multiple_choice(3)
easy.randomize_answer_list()
medium = database.get_random_multiple_choice(2)
medium.randomize_answer_list()
hard = database.get_random_multiple_choice(3)
hard.randomize_answer_list()
return render_template(
"multiple_choice.html",
title="Multiple Choice",
easy=easy,
# medium=medium,
# hard=hard,
)
@app.route("/category/multiple_choice/check_answer", methods=["GET"])
def check_answer():
question_id = request.args.get("question_id", type=int)
answer = request.args.get("answer", type=str)
if question_id is not None and answer is not None:
return jsonify(database.check_answer(question_id, answer))
2021-03-06 14:29:44 -08:00
if __name__ == "__main__":
app.run()