wanderhome-quiz/server/app/tools/data.py

22 lines
608 B
Python

from flask import current_app as app
import json
from os.path import isfile
from pathlib import Path
def check_file(filename:str):
data_dir = Path(app.config.get('DATA'))
if isfile(f'./{data_dir}/{filename}'): return True
return False
def load(filename:str):
data_dir = Path(app.config.get('DATA'))
with open(f'./{data_dir}/{filename}') as file: return json.load(file)
def render_questions():
data = load('questions.json')
for question in data:
_answers = [ answer['text'] for answer in question['answers'] ]
question['answers'] = _answers
return data