-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py.1
75 lines (55 loc) · 2.1 KB
/
index.py.1
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
# parameters: Dictionary, contains the field list
# - desc: field description
# - type: field type; values (t=text, n=number, hhmm = hour and minutes)
# - len: inputbox length
from mod_python import apache
from datetime import datetime
import utility
import cgi
import sqlite3 as lite
def index(req):
req.content_type = "text/html;charset=utf-8"
req.send_http_header()
req.write(utility.getInclude("header"))
req.write("<P><H3>Rasberry Pi Irrigation system status</H3><BR>Here are the last watering times \n<BR>")
req.write("<TABLE WIDTH='80%'>\n")
req.write("<THEAD><TR>")
req.write("<TD><B>Zone</B></TD>\n")
req.write("<TD><B>Start</B></TD>\n")
req.write("<TD><B>Stop</B></TD>\n")
req.write("</TR></THEAD>\n")
sqlCmd="SELECT e1.zone_id,strftime('%H:%M',e1.event_time),strftime('%H:%M',e2.event_time),strftime('%Y%m%d',e1.event_time) "
sqlCmd=sqlCmd+" FROM events e1, events e2 "
sqlCmd=sqlCmd+"WHERE e1.event_time >= datetime('now','-5 days') "
sqlCmd=sqlCmd+" AND e1.event = 1 AND e2.event = 0 "
sqlCmd=sqlCmd+" AND e2.event_time between e1.event_time AND datetime(e1.event_time,'+30 minutes') "
sqlCmd=sqlCmd+"ORDER BY e1.event_time DESC"
conn = lite.connect("/data/gardenpi.db")
cur = conn.cursor()
cur.execute(sqlCmd)
rows = cur.fetchall()
# req.write("<TABLE><THEAD><TD><B>Zone</B></TD><TD><B>Start</B></TD><TD><B>Stop</B></TD></THEAD>")
cRow = 1
breakDate = ""
if len(rows) >=1 :
for row in rows:
if breakDate != row[3]:
req.write("<TR>")
req.write("<TD COLSPAN=3>"+row[3])
req.write("</TD>")
req.write("</TR>")
breakDate = row[3]
req.write("<TR>")
req.write("<TD>"+str(row[0])+"</TD>")
req.write("<TD>"+row[1]+"</TD>")
req.write("<TD>"+row[2]+"</TD>")
req.write("</TR>")
#try:
# req.write(open('/var/www/raspberry/irrigationLog.txt').read())
#except:
# req.write("<TR><TD COLSPAN=3 ALIGN=CENTER>no watering available</TD></TR>")
req.write("</TABLE>\n")
req.write("</TABLE>\n")
req.write("</P>\n")
req.write(utility.getInclude("footer"))
return ;