diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a89b59f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.acceptSuggestionOnEnter": "on" +} diff --git a/influx_frontend.py b/influx_frontend.py index f8c93df..ef8b04b 100644 --- a/influx_frontend.py +++ b/influx_frontend.py @@ -22,9 +22,7 @@ client = influxdb_client.InfluxDBClient( def success(): return "Form success!" - -@app.route('/', methods=['GET', 'POST']) -def main_page(): +def fetch_timeseries_data(timestamp=None): query_api = client.query_api() query = 'from(bucket: "gas")\ |> range(start: -90d)\ @@ -64,7 +62,12 @@ def main_page(): continue else: newlist.append(value) + return newlist +@app.route('/', methods=['GET', 'POST']) +def main_page(): + ### Call fetch function + newlist = fetch_timeseries_data() # print(newlist) return render_template('index.html', data=newlist[:10]) @@ -125,6 +128,16 @@ def add_time(): return redirect(url_for('main_page')) +@app.route('/edit/') +def edit_odometer_entry(timestamp): + '''Retrieve the time entry from influxdb''' + print('Fetching data!') + ### Call fetch function + newlist = fetch_timeseries_data() + + # Fill entry_data with timestamp based data + entry_data = fetch_timeseries_data(timestamp) + return render_template('index.html', page_title="Edit Entry", timestamp_data=entry_data, data=newlist[:10]) @app.route('/repeat_last_odometer//') def repeat_last_odometer(odometer, winter=False): diff --git a/templates/index.html b/templates/index.html index cd3d65d..57c8d0f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,10 @@ {% extends "layout.html" %} {% block body %} +{% if page_title %} +

{{ page_title }}

+{% endif %} +