You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
770 B
Python
24 lines
770 B
Python
3 years ago
|
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)
|