quiz-the-word/application.py
Matthew Welch dd763deaea Moved database functions to database.py
main page shows 3 questions of easy medium and hard difficulty
2020-12-06 16:09:46 -08:00

53 lines
1.5 KiB
Python

from flask import Flask, render_template, redirect, url_for
from botocore.exceptions import ClientError
import database
application = Flask(__name__)
application.config.from_pyfile("config.py")
@application.route("/")
def index():
try:
easy = database.get_random_question_difficulty(1)
medium = database.get_random_question_difficulty(2)
hard = database.get_random_question_difficulty(3)
return render_template(
"index.html",
title="Quiz The Word",
easy=easy,
medium=medium,
hard=hard,
)
except ClientError as e:
return e.response["Error"]["Message"]
except Exception as e:
return str(e)
@application.route("/question/<int:question_index>")
def question(question_index):
try:
item_count = database.get_question_count()
if question_index < item_count:
item = database.get_question(question_index)
return render_template(
"index.html",
title="Bible Trivia",
question=item["Question"],
answer=item["Answer"],
addresses=item["Address"],
category=item["Category"],
difficulty=item["Difficulty"],
)
else:
return "<h1>Question not found.</h1>"
except ClientError as e:
return e.response["Error"]["Message"]
except Exception as e:
return str(e)
if __name__ == "__main__":
application.run()