Merge branch 'development' of ssh://git.vsnt.uk:2222/viveksantayana/wanderhome-quiz into development
This commit is contained in:
commit
da35b9c051
@ -2,7 +2,6 @@ import requests
|
||||
from typing import Union
|
||||
|
||||
SERVER = 'http://127.0.0.1:5000/'
|
||||
FETCH_PATH = 'api/fetch/'
|
||||
|
||||
INSTRUCTIONS = [
|
||||
'---- Instructions ----',
|
||||
@ -80,10 +79,10 @@ def validate_answer(answers:list, question:dict) -> bool:
|
||||
try: return all([check_range(answer=int(answer)) for answer in answers])
|
||||
except ValueError: return False
|
||||
|
||||
def render_questions() -> list:
|
||||
def render_questions() -> dict:
|
||||
answers = []
|
||||
try:
|
||||
questions = requests.get(url=f'{SERVER}{FETCH_PATH}questions/').json()
|
||||
questions = requests.get(url=f'{SERVER}/api/questions/').json()
|
||||
except Exception as exception:
|
||||
print(exception)
|
||||
quit()
|
||||
@ -102,7 +101,7 @@ def render_questions() -> list:
|
||||
print(exception)
|
||||
quit()
|
||||
|
||||
def render_results(results:list):
|
||||
def render_results(results:dict):
|
||||
print('\n---- Results ----\n')
|
||||
plural = len(results['playbooks']) > 1
|
||||
print(f'Your { "results are" if plural else "result is"}:')
|
||||
@ -117,13 +116,13 @@ def render_results(results:list):
|
||||
print(f'\n**The {name[0].upper()}{name[1:]}**\n(pp.{data["pages"]})\n')
|
||||
print(sanitise_text(data['flavour']),'\n')
|
||||
print(sanitise_text(data['blurb']),'\n')
|
||||
print('You are alive.\nYour care is ',sanitise_text(data['care']),'.\n')
|
||||
print('You are alive. Your care is ',sanitise_text(data['care']),'.\n')
|
||||
print('Your animal form is ', animals, '\n')
|
||||
print('You can always:')
|
||||
for action in data['actions']:
|
||||
print('-- ', sanitise_text(action))
|
||||
input('\nPress enter to continue.')
|
||||
print('\ny-- Your score for each playbook: --')
|
||||
print('\n-- Your score for each playbook: --')
|
||||
for playbook, score in results['all_playbooks'].items(): print(f'The {playbook[0].upper()}{playbook[1:]}: {score*"x"} ({round(100*score/results["max_score"])}%)')
|
||||
|
||||
def run_quiz():
|
||||
|
@ -1,6 +1,6 @@
|
||||
from .config import Development as Config
|
||||
from .models import *
|
||||
from .extensions import db
|
||||
from .extensions import cors, db
|
||||
|
||||
from flask import Flask
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
@ -10,6 +10,7 @@ def create_app():
|
||||
app.config.from_object(Config())
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto = 1, x_host = 1)
|
||||
|
||||
cors.init_app(app=app)
|
||||
db.init_app(app=app)
|
||||
|
||||
from .views import views
|
||||
|
@ -1,2 +1,4 @@
|
||||
from flask_cors import CORS
|
||||
cors = CORS()
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
db = SQLAlchemy()
|
@ -10,11 +10,9 @@ views = Blueprint(
|
||||
import_name=__name__
|
||||
)
|
||||
|
||||
@views.route('/fetch/<string:data_type>/')
|
||||
def _fetch(data_type):
|
||||
if not check_file(f'{data_type}.json'): return abort(404)
|
||||
if data_type == 'questions': return render_questions()
|
||||
return load(f'{data_type}.json')
|
||||
@views.route('/questions/')
|
||||
def _questions():
|
||||
return render_questions()
|
||||
|
||||
@views.route('/submit/', methods=['POST'])
|
||||
def _submit():
|
||||
|
Loading…
Reference in New Issue
Block a user