59 lines
1.8 KiB
Python
Executable File
59 lines
1.8 KiB
Python
Executable File
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Thu Aug 17 22:25:52 2017
|
|
|
|
@author: arofarn
|
|
"""
|
|
|
|
###########
|
|
# IMPORTS #
|
|
###########
|
|
|
|
from cameteo import *
|
|
from flask import render_template
|
|
from flask_bootstrap import Bootstrap
|
|
from flask_nav import Nav
|
|
from flask_nav.elements import *
|
|
|
|
########
|
|
# MAIN #
|
|
########
|
|
|
|
bootstrap = Bootstrap(app)
|
|
|
|
nav = Nav()
|
|
nav.init_app(app)
|
|
|
|
navbar = Navbar('Camétéo',
|
|
View('Accueil', 'index'),
|
|
Subgroup('Par données',
|
|
View("Température de l'air", 'by_data_type', dt='TA'),
|
|
View("Humidité relative", 'by_data_type', dt='HR'),
|
|
View("Pression atmosphérique",'by_data_type', dt='PA'),
|
|
),
|
|
Subgroup('Par capteur',
|
|
View("Capteur BME280", 'by_sensor', sens = 'AdaBME280_1')
|
|
)
|
|
)
|
|
nav.register_element('top', navbar)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
|
res = Data.query.filter(Data.dbdate >= date_deb)
|
|
return render_template('index.html', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15))
|
|
|
|
@app.route('/type_id=<dt>')
|
|
def by_data_type(dt):
|
|
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
|
res = Data.query.filter(Data.type_id == dt).filter(Data.dbdate >= date_deb)
|
|
return render_template('index.html', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15))
|
|
|
|
@app.route('/sensor_id=<sens>')
|
|
def by_sensor(sens):
|
|
date_deb = datetime.utcnow()-timedelta(seconds=3600)
|
|
res = Data.query.filter(Data.sensor_id == sens).filter(Data.dbdate >= date_deb)
|
|
return render_template('index.html', dat=res.order_by(Data.dbdate.desc()).paginate(per_page=15))
|
|
|
|
if __name__=="__main__":
|
|
app.run(host="0.0.0.0", debug=True) |