-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (47 loc) · 1.32 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#Main imports and package dependencies
import sqlite3
import datetime
from flask import Flask, jsonify, render_template
from bokeh.plotting import figure
from bokeh.resources import INLINE
from bokeh.embed import components
app = Flask(__name__)
@app.route('/')
def index():
return 'Welcome to charting with Bokeh!'
@app.route('/chart')
def chart():
p = figure(plot_width=1000, plot_height=600,
x_axis_type="datetime")
#add a line renderer
x = []
y = []
all_data = get_data()
for value in all_data:
date = datetime.datetime.fromtimestamp(value[0])
x.append(date)
y.append(value[1])
# create chart
p.line(x, y, line_width=2)
#create static files
js_resources = INLINE.render_js()
css_resources = INLINE.render_css()
script, div = components(p)
# render template
return render_template(
'chart.html',
plot_script=script,
plot_div=div,
js_resources=js_resources,
css_resources=css_resources)
@app.route('/data')
def get_data():
# Open database connection
with sqlite3.connect('greenhouse.db') as connection:
c = connection.cursor()
# Generate SQL query
c.execute("""SELECT * FROM greenhouse""")
rows = c.fetchall()
return rows
if __name__ == '__main__':
app.run(debug=True)