quiz-the-word/main.py

56 lines
1.5 KiB
Python

import os
from flask import Flask, render_template, request, jsonify
import database
app = Flask(__name__)
environment_configuration = os.environ['CONFIGURATION_SETUP']
app.config.from_object(environment_configuration)
@app.route("/")
def index():
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)
return render_template(
"hidden_answer.html",
title="Hidden Answer",
easy=easy,
medium=medium,
hard=hard,
)
@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))
if __name__ == "__main__":
app.run()