From 7f9016aa0010325a4a06691d0b5a61b92d284cd0 Mon Sep 17 00:00:00 2001 From: Yuval Adam Date: Fri, 30 May 2014 13:42:59 +0300 Subject: Fix data saving --- .gitignore | 2 ++ server.py | 10 ++++++++-- templates/home.html | 4 +--- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .gitignore 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', -- cgit v1.3.1