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
|
from typing import Union
|
||||||
|
|
||||||
SERVER = 'http://127.0.0.1:5000/'
|
SERVER = 'http://127.0.0.1:5000/'
|
||||||
FETCH_PATH = 'api/fetch/'
|
|
||||||
|
|
||||||
INSTRUCTIONS = [
|
INSTRUCTIONS = [
|
||||||
'---- 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])
|
try: return all([check_range(answer=int(answer)) for answer in answers])
|
||||||
except ValueError: return False
|
except ValueError: return False
|
||||||
|
|
||||||
def render_questions() -> list:
|
def render_questions() -> dict:
|
||||||
answers = []
|
answers = []
|
||||||
try:
|
try:
|
||||||
questions = requests.get(url=f'{SERVER}{FETCH_PATH}questions/').json()
|
questions = requests.get(url=f'{SERVER}/api/questions/').json()
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
print(exception)
|
print(exception)
|
||||||
quit()
|
quit()
|
||||||
@ -102,7 +101,7 @@ def render_questions() -> list:
|
|||||||
print(exception)
|
print(exception)
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
def render_results(results:list):
|
def render_results(results:dict):
|
||||||
print('\n---- Results ----\n')
|
print('\n---- Results ----\n')
|
||||||
plural = len(results['playbooks']) > 1
|
plural = len(results['playbooks']) > 1
|
||||||
print(f'Your { "results are" if plural else "result is"}:')
|
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(f'\n**The {name[0].upper()}{name[1:]}**\n(pp.{data["pages"]})\n')
|
||||||
print(sanitise_text(data['flavour']),'\n')
|
print(sanitise_text(data['flavour']),'\n')
|
||||||
print(sanitise_text(data['blurb']),'\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('Your animal form is ', animals, '\n')
|
||||||
print('You can always:')
|
print('You can always:')
|
||||||
for action in data['actions']:
|
for action in data['actions']:
|
||||||
print('-- ', sanitise_text(action))
|
print('-- ', sanitise_text(action))
|
||||||
input('\nPress enter to continue.')
|
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"])}%)')
|
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():
|
def run_quiz():
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from .config import Development as Config
|
from .config import Development as Config
|
||||||
from .models import *
|
from .models import *
|
||||||
from .extensions import db
|
from .extensions import cors, db
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
@ -10,6 +10,7 @@ def create_app():
|
|||||||
app.config.from_object(Config())
|
app.config.from_object(Config())
|
||||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto = 1, x_host = 1)
|
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto = 1, x_host = 1)
|
||||||
|
|
||||||
|
cors.init_app(app=app)
|
||||||
db.init_app(app=app)
|
db.init_app(app=app)
|
||||||
|
|
||||||
from .views import views
|
from .views import views
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
from flask_cors import CORS
|
||||||
|
cors = CORS()
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
@ -10,11 +10,9 @@ views = Blueprint(
|
|||||||
import_name=__name__
|
import_name=__name__
|
||||||
)
|
)
|
||||||
|
|
||||||
@views.route('/fetch/<string:data_type>/')
|
@views.route('/questions/')
|
||||||
def _fetch(data_type):
|
def _questions():
|
||||||
if not check_file(f'{data_type}.json'): return abort(404)
|
return render_questions()
|
||||||
if data_type == 'questions': return render_questions()
|
|
||||||
return load(f'{data_type}.json')
|
|
||||||
|
|
||||||
@views.route('/submit/', methods=['POST'])
|
@views.route('/submit/', methods=['POST'])
|
||||||
def _submit():
|
def _submit():
|
||||||
|
Loading…
Reference in New Issue
Block a user