Started writing data and server
This commit is contained in:
0
server/app/tools/__init__.py
Normal file
0
server/app/tools/__init__.py
Normal file
22
server/app/tools/data.py
Normal file
22
server/app/tools/data.py
Normal file
@ -0,0 +1,22 @@
|
||||
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
|
||||
|
Reference in New Issue
Block a user