From 23085de24e811fc1dbc27ab804f69c5ad11e87cb Mon Sep 17 00:00:00 2001 From: Alexander Hosking Date: Tue, 27 Dec 2016 09:30:20 -0500 Subject: [PATCH] First version of insert with hardcoded db and measurement --- influx_frontend.py | 37 ++++++++++++++++++++++++++++++++++--- templates/index.html | 3 ++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/influx_frontend.py b/influx_frontend.py index bb019ee..cddb47f 100644 --- a/influx_frontend.py +++ b/influx_frontend.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template +from flask import Flask, request, render_template app = Flask(__name__) from influxdb import InfluxDBClient @@ -16,9 +16,40 @@ def success(): def main_page(): return render_template('index.html') -@app.route('/add_time') +@app.route('/add_time', methods=['POST']) def add_time(): - return 'admin' +# database = request.form['db'] +# table = request.form['table'] + date = request.form['date'] + time = request.form['time'] + odometer = request.form['odometer'] + oilhealth= request.form['oilhealth'] + fuel = request.form['fuel'] + fuelcost = request.form['fuelcost'] + winter = request.form['winter'] + + json_body = [ + { + "time": date + "T" + time + "Z", + "measurement": "odyssey", + "fields": { + "odometer": odometer, + "oilhealth": oilhealth, + "fuel": fuel, + "fuelcost": fuelcost, + "winter": winter + } + } + ] + + client = InfluxDBClient('localhost', 8086, 'root', 'root', 'gas') + + print ("Submitting data to DB: {0}".format(json_body)) + client.write_points(json_body) + + + + return render_template('index.html') @app.route('/admin') def admin_index(): diff --git a/templates/index.html b/templates/index.html index d13f396..369e299 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,7 +3,7 @@
-
+