-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.py
executable file
·76 lines (52 loc) · 1.55 KB
/
web.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/python
from flask import *
import os
import sqlite3
app = Flask(__name__)
def home():
return render_template('home.html')
@app.route('/raw')
def raw():
return open('temp.data').read()
@app.route('/')
@app.route('/temp')
def temp():
graphdata = []
con = get_dbhandle()
cur = con.cursor()
cur.execute('select timestamp, insidetemp_f, outsidetemp_f from trends')
while True:
row = cur.fetchone()
if row == None:
break
graphdata.append("['%s', %s, %s]" % (row[0], row[1], row[2]))
displaydata = "[['Date','Inside','Outside']," + ",".join(graphdata) + "]"
data = """
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable(%data%);
var options = {
title: 'Historical Temp'
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html> """.replace('%data%', displaydata)
return data
##return '<pre>' + open('temp.data').read()
def get_dbhandle():
con = None
con = sqlite3.connect('/var/lib/rpi-datalogger/database.db')
return con
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0',port=80)