summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-06-06 23:02:37 +0300
committerYuval Adam <yuv.adm@gmail.com>2014-06-06 23:02:37 +0300
commit2e1664c0162891e44b36f5d4966411e3c93c1323 (patch)
treeeb66f8fde8cc44e53487209e54c430701618844f
parentc51ccd1953a9c2e08e81f546dd2c99f00945a17b (diff)
Save raw files
-rw-r--r--server.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/server.py b/server.py
index 227ba9a..aed0c7b 100644
--- a/server.py
+++ b/server.py
@@ -11,6 +11,18 @@ app = Flask(__name__)
def home():
return render_template('home.html')
+def save_json(data, filename):
+ with open(DATA_DIR.child(filename), 'w') as f:
+ json.dump(data, f, indent=2)
+
+def save_raw(data, filename):
+ with open(DATA_DIR.child(filename), 'w') as f:
+ f.write('{}\n\n'.format(data['tempo']))
+ for tree in data['trees']:
+ for row in tree:
+ f.write(''.join(map(str, row)) + '\n')
+ f.write('\n')
+
@app.route('/data', methods=['POST', 'GET'])
def data():
if request.method == 'GET':
@@ -18,9 +30,9 @@ def data():
return jsonify(json.load(f))
elif request.method == 'POST':
ts = datetime.now().strftime('%Y%m%d_%H%M%S')
- for filename in ('data.json', 'data.{}.json'.format(ts)):
- with open(DATA_DIR.child(filename), 'w') as f:
- json.dump(request.json, f, indent=2)
+ save_json(request.json, 'data.json')
+ save_json(request.json, 'data.{}.json'.format(ts))
+ save_raw(request.json, 'data.txt')
return 'ok'
if __name__ == '__main__':