Compare commits

..

No commits in common. "94c493fa9bbf3a449c9a1e9ee8a393f7f21e47d7" and "2c461ad4f725a5bd945e8ababba5fa4cd18678b2" have entirely different histories.

4 changed files with 26 additions and 28 deletions

0
docker_run.sh Executable file → Normal file
View File

View File

@ -8,14 +8,14 @@ from influxdb_client.client.write_api import SYNCHRONOUS
config = dotenv_values(".env") config = dotenv_values(".env")
print(config)
app = Flask(__name__) app = Flask(__name__)
client = influxdb_client.InfluxDBClient( def db_main(host='localhost', port=8086):
url=config['DB_URL'], user = 'root'
token=config['DB_TOKEN'], password = 'root'
org=config['DB_ORG'] dbname = 'gas'
)
@app.route('/success') @app.route('/success')
def success(): def success():
@ -23,22 +23,14 @@ def success():
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
def main_page(): def main_page():
query_api = client.query_api() client = influxdb_client.InfluxDBClient(
query = 'from(bucket: "gas")\ url=config['DB_URL'],
|> range(start: -96h)\ token=config['DB_TOKEN'],
|> filter(fn: (r) => r["_measurement"] == "2016_odyssey")\ org=config['DB_ORG']
|> filter(fn: (r) => r["_field"] == "odometer")' )
#query = 'select TOP(odometer, 5) from odyssey' #query = 'select TOP(odometer, 5) from odyssey'
#data = client.query(query) #data = client.query(query)
result = query_api.query(org=config['DB_ORG'], query=query) data = []
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)
data= results
return render_template('index.html', data=data) return render_template('index.html', data=data)
@app.route('/add_time', methods=['POST', 'GET']) @app.route('/add_time', methods=['POST', 'GET'])
@ -87,12 +79,16 @@ def add_time():
print() print()
print(dt) print(dt)
print() 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) write_api = client.write_api(write_options=SYNCHRONOUS)
p = influxdb_client.Point("2016_odyssey").time(timestamp).field("odometer", float(odometer)).field("oilhealth", oilhealth)\ p = influxdb_client.Point("2016_odyssey").time(timestamp).field("odometer", float(odometer))
.field("fuel", fuel).field("fuelcost", fuelcost).field("winter", winter)
write_api.write(bucket="gas", org=config['DB_ORG'], record=p) write_api.write(bucket="gas", org=config['DB_ORG'], record=p)
print ("Submitting data to DB: {0}".format(json_body)) print ("Submitting data to DB: {0}".format(json_body))
#client.write_points(json_body) client.write_points(json_body)
@ -111,4 +107,4 @@ def logout():
pass pass
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port='9001') app.run(debug=True, host='0.0.0.0')

View File

@ -60,9 +60,11 @@
Last Mileage Last Mileage
<ul> <ul>
{% for point in data %} {% for point in data %}
{% for item in point %}
<li> <li>
{{ point[0] }} = {{ point[1] }}, {{point[2]}} {{ item['top'] }}
</li> </li>
{% endfor %}
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}
</ul> </ul>

View File

@ -41,7 +41,7 @@
<!--<li class="active"><a href="/">Inventory<span class="sr-only">(current)</span></a></li>--> <!--<li class="active"><a href="/">Inventory<span class="sr-only">(current)</span></a></li>-->
<li><a href="{{ url_for('main_page') }}">Home</a></li> <li><a href="{{ url_for('main_page') }}">Home</a></li>
</ul> </ul>
<!-- <ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
{% if not session.logged_in %} {% if not session.logged_in %}
<li> <li>
@ -59,7 +59,7 @@
</a> </a>
</li> </li>
{% endif %} {% endif %}
</ul> --> </ul>
</div><!-- /.navbar-collapse --> </div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid --> </div><!-- /.container-fluid -->
</nav> </nav>