diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2014-06-07 21:13:54 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2014-06-07 21:13:54 +0300 |
| commit | 7e75dfdd983abf915b4201c99b16d60cd5419101 (patch) | |
| tree | d8c770cee26575dcaa3041648781872cc210c848 /server.py | |
| parent | 48d3e0aab0a7125f563f41c269e627231fd12180 (diff) | |
Final sequence stuff
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -11,6 +11,26 @@ app = Flask(__name__) def home(): return render_template('home.html') +@app.route('/sequence', methods=['GET']) +@app.route('/sequence/<name>', methods=['POST', 'GET']) +def sequence(name=None): + sequences_dir = DATA_DIR.child('sequences') + + if name and request.method == 'GET': + with open(sequences_dir.child('{}.json'.format(name)), 'r') as f: + return jsonify(json.load(f)) + + sequences = [{ + 'name': sequence.name.split('.json')[0], + 'pattern': json.load(open(sequence, 'r')) + } for sequence in sequences_dir.walk(pattern='*.json')] + + if request.method == 'POST': + with open(sequences_dir.child('{}.json'.format(name)), 'w') as f: + json.dump(data, f, indent=2) + + return render_template('sequence.html', sequences=sequences) + def save_json(data, filename): with open(DATA_DIR.child(filename), 'w') as f: json.dump(data, f, indent=2) |
