import argparse
import hashlib
import json
import cPickle
from datetime import datetime
from flask import Flask
from flask import request
from flask import render_template
from flask import redirect, url_for

data = {
    "when": datetime.now().isoformat(),
    "error": 0,
    "warning": 0,
    "lint": 0,
    "success": True,
}

cPickle.dump(data, file("database", "wb"))

app = Flask(__name__)
app.debug = True

@app.route("/")
def index():
    return render_template('index.html')


@app.route("/api/put")
def put_data():
    data = json.loads(request.args['json'])
    cPickle.dump(data, file("database", "wb"))
    return 'OK'

@app.route("/api/get")
def get_data():
    data = cPickle.load(file("database", "rb"))
    return json.dumps(data)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Visualizing server')
    parser.add_argument('--port', default=8104, type=int)

    args = parser.parse_args()
    app.run('0.0.0.0', args.port)

@@ -200,16 +200,41 @@
  url_for
+%0Aimport os%0Aimport sqlite3
 %0A%0Adata =
@@ -397,382 +397,1704 @@
 ))%0A%0A
-app = Flask(__name__)%0Aapp.debug = True%0A%0A@app.route(%22/%22)%0Adef index():%0A    return render_template('index.html')%0A%0A%0A@app.route(%22/api/put%22)%0Adef put_data():%0A    data = json.loads(request.args%5B'json'%5D)%0A    cPickle.dump(data, file(%22database%22, %22wb%22))%0A    return 'OK'%0A%0A@app.route(%22/api/get%22)%0Adef get_data():%0A    data = cPickle.load(file(%22database%22, %22rb%22))%0A    return json.dumps(data)%0A
+DATABASE = 'database.sqlite'%0Aif not os.path.isfile(DATABASE):%0A    # Create table%0A    conn = sqlite3.connect(DATABASE)%0A    cursor = conn.cursor()%0A    cursor.execute('''CREATE TABLE log%0A             (when_ TEXT, user TEXT, proj TEXT,%0A              error INTEGER, warning INTEGER, lint INTEGER,%0A              success INTEGER, message TEXT)''')%0A    conn.commit()%0A    conn.close()%0A%0A%0A%0Aapp = Flask(__name__)%0Aapp.debug = True%0A%0A@app.route(%22/%22)%0Adef index():%0A    return render_template('index.html')%0A%0A%0A@app.route(%22/api/put%22)%0Adef put_data():%0A    data = json.loads(request.args%5B'json'%5D)%0A    cPickle.dump(data, file(%22database%22, %22wb%22))%0A%0A    when = datetime.now().isoformat()%0A    conn = sqlite3.connect(DATABASE)%0A    cursor = conn.cursor()%0A    cursor.execute(%0A        '''INSERT INTO log VALUES(?, ?, ?, ?, ?, ?, ?, ?)''',%0A        (when, 'default-user', 'default-proj',%0A         data%5B'error'%5D, data%5B'warning'%5D, data%5B'lint'%5D,%0A         data%5B'success'%5D, data.get('message', '')))%0A    conn.commit()%0A    conn.close()%0A    return 'OK'%0A%0A@app.route(%22/api/get%22)%0Adef get_data():%0A    data = cPickle.load(file(%22database%22, %22rb%22))%0A    return json.dumps(data)%0A%0A%0A@app.route(%22/api/get_multi%22)%0Adef get_data_multi():%0A    when_ = request.args.get('when', datetime.now().isoformat())%0A    number = request.args.get('number', 10)%0A%0A    conn = sqlite3.connect(DATABASE)%0A    cursor = conn.cursor()%0A    cursor.execute(%0A        '''SELECT error, warning, lint FROM log WHERE when_ %3C ? AND user = ? AND proj = ? LIMIT ?''',%0A        (when_, 'default-user', 'default-proj', number))%0A%0A    data = cursor.fetchall()%0A    conn.commit()%0A    conn.close()%0A    #data = map(lambda (e, w, l): dict(error=e, warn=w, lint=l), data)%0A    return json.dumps(data)
 %0A%0Aif

add sqlite to save old values