Upgrade to influx2

This commit is contained in:
Alexander Hosking 2022-06-28 07:42:26 -04:00
parent 18ce2b5399
commit 2c461ad4f7
3 changed files with 38 additions and 13 deletions

3
docker_run.sh Normal file
View File

@ -0,0 +1,3 @@
docker run -p 8086:8086 \
-v $PWD:/var/lib/influxdb2 \
influxdb:2.0

View File

@ -1,9 +1,16 @@
from flask import Flask, request, render_template, redirect, url_for
from time import strftime
import datetime
import pendulum
from dotenv import dotenv_values
import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS
config = dotenv_values(".env")
print(config)
app = Flask(__name__)
from influxdb import InfluxDBClient
def db_main(host='localhost', port=8086):
user = 'root'
@ -16,9 +23,14 @@ def success():
@app.route('/', methods=['GET', 'POST'])
def main_page():
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'gas')
query = 'select TOP(odometer, 5) from odyssey'
data = client.query(query)
client = influxdb_client.InfluxDBClient(
url=config['DB_URL'],
token=config['DB_TOKEN'],
org=config['DB_ORG']
)
#query = 'select TOP(odometer, 5) from odyssey'
#data = client.query(query)
data = []
return render_template('index.html', data=data)
@app.route('/add_time', methods=['POST', 'GET'])
@ -62,9 +74,19 @@ def add_time():
}
}
]
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'gas')
timestamp = date + "T" + time + "Z"
dt = pendulum.parse(timestamp)
print()
print(dt)
print()
client = influxdb_client.InfluxDBClient(
url=config['DB_URL'],
token=config['DB_TOKEN'],
org=config['DB_ORG']
)
write_api = client.write_api(write_options=SYNCHRONOUS)
p = influxdb_client.Point("2016_odyssey").time(timestamp).field("odometer", float(odometer))
write_api.write(bucket="gas", org=config['DB_ORG'], record=p)
print ("Submitting data to DB: {0}".format(json_body))
client.write_points(json_body)

View File

@ -1,14 +1,14 @@
wheel==0.29.0
certifi==2022.6.15
click==6.6
Flask==0.11.1
Flask-WTF==0.13.1
influxdb==4.0.0
influxdb-client==1.30.0
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
python-dateutil==2.6.0
pendulum==2.1.2
pytz==2016.10
pytzdata==2020.1
requests==2.12.4
Rx==3.2.0
six==1.10.0
urllib3==1.26.9
Werkzeug==0.11.11
WTForms==2.1