53 lines
1.5 KiB
Python
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()
|