-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_buzz.py
144 lines (116 loc) · 3.6 KB
/
app_buzz.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python
#
__author__ = 'Cameron Rodda'
__date__ = 'Sept 2014'
import os
import cherrypy
import jinja2
import sqlite3 as lite
import datetime
BASE_DIR = os.path.dirname(os.path.abspath(__file__)).replace('\\','/')#to fix windows errors with os.path
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates/')
STYLES_DIR = os.path.join(BASE_DIR,'styles/')
JS_DIR = os.path.join(BASE_DIR,'js/')
IMG_DIR = os.path.join(BASE_DIR,'images/')
DB_DIR = os.path.join(BASE_DIR,'db/')
ICON_FILE = "%s/favicon.ico" % BASE_DIR
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(TEMPLATE_DIR), autoescape=True)
try:
pass
except lite.Error, e:
cherrypy.log.error(e)
raise e
class Buzz(object):
@cherrypy.expose
def index(self):
cherrypy.log.error(BASE_DIR)
t = jinja_env.get_template('index.html')
return t.render(name = "Camerons")
@cherrypy.expose
def svg(self):
t = jinja_env.get_template('test_svg.html')
return t.render()
@cherrypy.expose
def config(self):
t = jinja_env.get_template('config.html')
return t.render(name = "Camerons")
@cherrypy.expose
def hives(self):
t = jinja_env.get_template('hives.html')
return t.render(name = "Camerons")
@cherrypy.expose
def observe(self, **kws):
db = lite.connect("%sBuzzLight.db" % DB_DIR)
cur = db.cursor()
if "add_entry" in kws:
name = kws['name']
date = kws['date']
hive = kws['hive']
notes = kws['notes']
weather = kws['weather']
cur.execute("INSERT INTO beelog (date_log,user,hive,notes,weather) "\
"VALUES (?,?,?,?,?)", (date,name,hive,notes,weather) )
db.commit()
cur.execute("SELECT * FROM beelog ORDER BY date(date_log) DESC")
data = cur.fetchall()
db.close()
#cherrypy.log.error(type(data).string)
current_date = datetime.datetime.now().strftime("%Y/%m/%d")
t = jinja_env.get_template('observe.html')
return t.render(entries=data, now=current_date)
@cherrypy.expose
def location(self, **kws):
db = lite.connect("%sBuzzLight.db" % DB_DIR)
cur = db.cursor()
if "add_location" in kws:
latti = kws['latt']
longi = kws['long']
hive = kws['hive']
cur.execute("INSERT INTO LOCATION (latt,long,hive) "\
"VALUES (?,?,?)", (latti,longi,hive))
db.commit()
cur.execute("SELECT * FROM LOCATION")
data = cur.fetchall()
db.close()
t = jinja_env.get_template('location.html')
return t.render(locations=data)
cherrypy.config.update({
'server.socket_host': '127.0.0.1',
'server.socket_port': 7000
})
config = {
'/':
{
'tools.staticdir.debug': True,
'log.screen': True,
},
'/templates':
{
'tools.staticdir.on': True,
'tools.staticdir.dir': TEMPLATE_DIR
},
'/styles':
{
'tools.staticdir.on': True,
'tools.staticdir.dir': STYLES_DIR
},
'/js':
{
'tools.staticdir.on': True,
'tools.staticdir.dir': JS_DIR
},
'/images':
{
'tools.staticdir.on': True,
'tools.staticdir.dir': IMG_DIR
},
'/favicon.ico':
{
'tools.staticfile.on': True,
'tools.staticfile.filename': ICON_FILE
}
}
cherrypy.tree.mount(Buzz(),'/',config=config)
cherrypy.engine.autoreload.on = True
cherrypy.engine.autoreload.files.add('app_buzz.py')
cherrypy.engine.start()