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

14 lines
407 B
Python
Raw Normal View History

2022-08-24 15:55:53 +01:00
from flask import current_app as app
import json
from os.path import isfile
from pathlib import Path
def check_file(filename:str) -> bool:
2022-08-24 15:55:53 +01:00
data_dir = Path(app.config.get('DATA'))
if isfile(f'./{data_dir}/{filename}'): return True
return False
def load(filename:str) -> dict:
2022-08-24 15:55:53 +01:00
data_dir = Path(app.config.get('DATA'))
with open(f'./{data_dir}/{filename}') as file: return json.load(file)