From f9d76a12eada6b7a23177be25104681be9af47a8 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Mon, 29 Aug 2022 19:32:19 +0100 Subject: [PATCH 1/6] Changed annotation --- server/CLIent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/CLIent.py b/server/CLIent.py index 85b06d1..08e2b18 100644 --- a/server/CLIent.py +++ b/server/CLIent.py @@ -80,7 +80,7 @@ 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() @@ -102,7 +102,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"}:') From 1218dbc911be65ae5a8b153edc33879d21336525 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Mon, 29 Aug 2022 19:33:42 +0100 Subject: [PATCH 2/6] Fixed a typo --- server/CLIent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/CLIent.py b/server/CLIent.py index 08e2b18..b500ae6 100644 --- a/server/CLIent.py +++ b/server/CLIent.py @@ -123,7 +123,7 @@ def render_results(results:dict): 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(): From a50926b192ac92c67f735f54c916264ef5fba230 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Mon, 29 Aug 2022 19:41:32 +0100 Subject: [PATCH 3/6] Typo --- server/CLIent.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/CLIent.py b/server/CLIent.py index b500ae6..3d4f8da 100644 --- a/server/CLIent.py +++ b/server/CLIent.py @@ -117,7 +117,7 @@ def render_results(results:dict): 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']: From f7c6081ca078131cf82a7edc0ebb4d17eddac7bf Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Wed, 31 Aug 2022 00:48:13 +0100 Subject: [PATCH 4/6] Simplified question route --- server/app/views.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/app/views.py b/server/app/views.py index 2bf37bb..9585ada 100644 --- a/server/app/views.py +++ b/server/app/views.py @@ -9,11 +9,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(): From ce4694830def7c4cfbe1926ddb7b57e608eb926b Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Wed, 31 Aug 2022 00:48:36 +0100 Subject: [PATCH 5/6] Added CORS extension --- server/app/__init__.py | 3 ++- server/app/extensions.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) 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 From cadccf1a53063b8892a0e7b42ae6496c2801dce0 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Wed, 31 Aug 2022 00:49:00 +0100 Subject: [PATCH 6/6] Updated API path --- server/CLIent.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/CLIent.py b/server/CLIent.py index 3d4f8da..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 ----', @@ -83,7 +82,7 @@ def validate_answer(answers:list, question:dict) -> bool: 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()