summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <yuv.adm@gmail.com>2014-05-30 13:42:59 +0300
committerYuval Adam <yuv.adm@gmail.com>2014-05-30 13:42:59 +0300
commit7f9016aa0010325a4a06691d0b5a61b92d284cd0 (patch)
treeb6de791321ecf19d7d3b416b751b22ffa677305a
parenteb671b4075809b39071868e580276d0a842944ff (diff)
Fix data saving
-rw-r--r--.gitignore2
-rw-r--r--server.py10
-rw-r--r--templates/home.html4
3 files changed, 11 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a22d4a8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.pyc
+/data
diff --git a/server.py b/server.py
index fa79216..e1129a8 100644
--- a/server.py
+++ b/server.py
@@ -1,8 +1,11 @@
+import json
+
+from datetime import datetime
from flask import Flask
from flask import render_template, request
from unipath import FSPath as Path
-DATA_DIR = Path(__file__).absolute().child('data')
+DATA_DIR = Path(__file__).absolute().ancestor(1).child('data')
app = Flask(__name__)
@@ -15,7 +18,10 @@ def data():
if request.method == 'GET':
return 'hai'
elif request.method == 'POST':
- print request.json
+ 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)
return 'ok'
if __name__ == '__main__':
diff --git a/templates/home.html b/templates/home.html
index af51211..4aba7f2 100644
--- a/templates/home.html
+++ b/templates/home.html
@@ -18,7 +18,6 @@
};
function save_data(data) {
-
var data = {
tempo: 500,
trees: []
@@ -34,10 +33,9 @@
tree_data.push(vals);
});
data.trees.push(tree_data);
- // console.log(tree.attr('data-light-tree'));
});
- console.log(data);
+ console.log('Saved:', data);
$.ajax({
type: 'POST',