KemoFureApi/modules/JapariSling/endpoints/get.py

24 lines
751 B
Python

import os
import json
from flask_restful import Resource
from flask import abort, request, current_app as app
class Get(Resource):
def get(self):
dir_name = os.path.join(app.root_path, 'data', 'JapariSling')
files = [json.loads(read_file(os.path.join(dir_name, f))) for f in os.listdir(dir_name) if os.path.isfile(os.path.join(dir_name, f))]
files = files[:10]
files = {"levels": files}
response = app.response_class(
response = json.dumps(files),
status=200,
mimetype='application/json'
)
response.headers.add("Access-Control-Allow-Origin", "*")
return response
def read_file(path):
with open(path, 'r') as f:
return f.read()