-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
85 lines (65 loc) · 2.17 KB
/
client.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
import os
from bottle import route, run, template, static_file, redirect, request
import server as s
import web_config as config
APP_PATH = os.path.dirname(os.path.abspath(__file__))
os.environ['PYTHON_EGG_CACHE'] = '__pycache__'
def check_login():
if (s.validate_login()):
return True
else:
redirect (config.WEBROOT + "/login")
return False
@route(config.WEBROOT + '/')
def index():
if check_login():
_response = s.get()
if (_response["Status"]):
return template('index_template', Status=_response["Current_State"]
, Current_Temperature=_response["Current_Temperature"]
, Current_Humidity=_response["Current_Humidity"]
, Target_Temperature=_response["Target_Temperature"]
, Current_Mode=_response["Current_Mode"]
, Stage=_response["Stage"]
, Schedule=_response["Schedule"]
,Web_Root = config.WEBROOT)
else:
return("error_template")
@route(config.WEBROOT + '/set/<mode>/<temp>')
def set(mode, temp):
if check_login():
schedule = request.GET.get('sch')
if (len(schedule)>15):
s.set(mode,temp, schedule)
else:
s.set(mode,temp)
return redirect(config.WEBROOT + '/')
@route(config.WEBROOT + '/login')
def login():
return template('login_template',Message=None, Web_Root = config.WEBROOT)
@route(config.WEBROOT + '/login', method='POST')
def do_login():
pin = request.forms.get('pin')
if s.login(pin)["Status"]:
redirect (config.WEBROOT + '/')
else:
return template('login_template', Message='Login incorrect',Web_Root = config.WEBROOT)
# static files
@route(config.WEBROOT + '/images/<filename>')
def images(filename):
return static_file(filename, root= APP_PATH + '/images')
@route(config.WEBROOT + '/css/<filename>')
def css(filename):
return static_file(filename, root=APP_PATH + '/css')
@route(config.WEBROOT + '/fonts/<filename>')
def css(filename):
return static_file(filename, root=APP_PATH + '/fonts')
@route(config.WEBROOT + '/js/<filename>')
def css(filename):
return static_file(filename, root=APP_PATH + '/js')
if __name__=='__main__':
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
s.initialize()
run(host='0.0.0.0', port=81)