2016-12-27 14:30:20 +00:00
|
|
|
from flask import Flask, request, render_template
|
2016-12-20 06:50:26 +00:00
|
|
|
|
2016-12-06 12:46:40 +00:00
|
|
|
app = Flask(__name__)
|
|
|
|
from influxdb import InfluxDBClient
|
|
|
|
|
|
|
|
def db_main(host='localhost', port=8086):
|
|
|
|
user = 'root'
|
|
|
|
password = 'root'
|
|
|
|
dbname = 'gas'
|
|
|
|
|
2016-12-20 06:50:26 +00:00
|
|
|
@app.route('/success')
|
|
|
|
def success():
|
|
|
|
return "Form success!"
|
|
|
|
|
2016-12-27 03:43:38 +00:00
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
2016-12-20 06:50:26 +00:00
|
|
|
def main_page():
|
2016-12-27 03:43:38 +00:00
|
|
|
return render_template('index.html')
|
|
|
|
|
2016-12-27 14:30:20 +00:00
|
|
|
@app.route('/add_time', methods=['POST'])
|
2016-12-27 03:43:38 +00:00
|
|
|
def add_time():
|
2016-12-27 14:30:20 +00:00
|
|
|
# database = request.form['db']
|
|
|
|
# table = request.form['table']
|
|
|
|
date = request.form['date']
|
|
|
|
time = request.form['time']
|
|
|
|
odometer = request.form['odometer']
|
|
|
|
oilhealth= request.form['oilhealth']
|
|
|
|
fuel = request.form['fuel']
|
|
|
|
fuelcost = request.form['fuelcost']
|
|
|
|
winter = request.form['winter']
|
|
|
|
|
|
|
|
json_body = [
|
|
|
|
{
|
|
|
|
"time": date + "T" + time + "Z",
|
|
|
|
"measurement": "odyssey",
|
|
|
|
"fields": {
|
|
|
|
"odometer": odometer,
|
|
|
|
"oilhealth": oilhealth,
|
|
|
|
"fuel": fuel,
|
|
|
|
"fuelcost": fuelcost,
|
|
|
|
"winter": winter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
client = InfluxDBClient('localhost', 8086, 'root', 'root', 'gas')
|
|
|
|
|
|
|
|
print ("Submitting data to DB: {0}".format(json_body))
|
|
|
|
client.write_points(json_body)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render_template('index.html')
|
2016-12-27 03:43:38 +00:00
|
|
|
|
|
|
|
@app.route('/admin')
|
|
|
|
def admin_index():
|
|
|
|
return 'admin'
|
|
|
|
|
|
|
|
@app.route('/login')
|
|
|
|
def login():
|
|
|
|
pass
|
|
|
|
|
|
|
|
@app.route('/logout')
|
|
|
|
def logout():
|
|
|
|
pass
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
app.run(debug=True, host='0.0.0.0')
|