Add Repeat Button and Function
This commit is contained in:
parent
6bb2be70f7
commit
1e68ae8573
@ -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')
|
||||
|
Loading…
Reference in New Issue
Block a user