From 1e68ae857388b931d1dcba3456e492159d571acd Mon Sep 17 00:00:00 2001 From: ahosking Date: Fri, 15 Jul 2022 01:05:23 -0400 Subject: [PATCH] Add Repeat Button and Function --- influx_frontend.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/influx_frontend.py b/influx_frontend.py index 45e0c4d..2af2f5e 100644 --- a/influx_frontend.py +++ b/influx_frontend.py @@ -32,12 +32,12 @@ def main_page(): #query = 'select TOP(odometer, 5) from odyssey' #data = client.query(query) result = query_api.query(org=config['DB_ORG'], query=query) - print(result) + # print(result) results = [] for table in result: for record in table.records: results.append((record.get_time(), record.get_field(), record.get_value())) - print(results) + # print(results) data= results return render_template('index.html', data=data) @@ -82,6 +82,7 @@ def add_time(): } } ] + timestamp = date + "T" + time + "Z" dt = pendulum.parse(timestamp) print() @@ -96,6 +97,40 @@ def add_time(): + return redirect(url_for('main_page')) + +@app.route('/repeat_last_odometer') +def repeat_last_odometer(): + query_api = client.query_api() + query = 'from(bucket: "gas")\ + |> range(start: -7d)\ + |> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\ + |> filter(fn: (r) => r["_field"] == "odometer")\ + |> last()' + + result = query_api.query(org=config['DB_ORG'], query=query) + print() + print() + print(result) + print() + results = {} + for table in result: + for record in table.records: + results[record.get_field()] = record.get_value() + results['time'] = record.get_time() + # .append((record.get_time(), record.get_field(), record.get_value())) + print(results) + print() + + date = strftime("%Y-%m-%d") + time = strftime("%H:%M:%S") + timestamp = date + "T" + time + "Z" + + print(results['odometer']) + + write_api = client.write_api(write_options=SYNCHRONOUS) + p = influxdb_client.Point("2016_odyssey").time(timestamp).field("odometer", float(results['odometer'])) + write_api.write(bucket="gas", org=config['DB_ORG'], record=p) return redirect(url_for('main_page')) @app.route('/admin')