from flask import Blueprint, render_template, request from datetime import datetime import json import os bp = Blueprint('module', __name__, url_prefix="/") @bp.route('/', methods=['GET', 'POST']) def module(): if request.method == 'POST': preset = {} for key in request.form.keys(): preset[key] = request.form.get(key) name = preset.get('name', '') filename = f"{name}_{datetime.now().strftime('%Y-%m-%d_%H-%M-%S')}.json" with open(os.path.join(os.environ.get('MODULES'), filename), 'w') as f: f.write(json.dumps(preset)) modules = [os.path.splitext(filename)[0] for filename in os.listdir(os.environ.get('MODULES'))] return render_template('module.html', modules=modules)