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 --- server.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'server.py') 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__': -- cgit v1.3.1