diff --git a/server/CLIent.py b/server/CLIent.py index 85b06d1..66c4c41 100644 --- a/server/CLIent.py +++ b/server/CLIent.py @@ -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(): diff --git a/server/app/__init__.py b/server/app/__init__.py index 3ee291b..7a06640 100644 --- a/server/app/__init__.py +++ b/server/app/__init__.py @@ -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 diff --git a/server/app/extensions.py b/server/app/extensions.py index 589c64f..5e5713d 100644 --- a/server/app/extensions.py +++ b/server/app/extensions.py @@ -1,2 +1,4 @@ +from flask_cors import CORS +cors = CORS() from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() \ No newline at end of file diff --git a/server/app/views.py b/server/app/views.py index aa7de9b..f1fe6e9 100644 --- a/server/app/views.py +++ b/server/app/views.py @@ -10,11 +10,9 @@ views = Blueprint( import_name=__name__ ) -@views.route('/fetch//') -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():