-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
62 lines (52 loc) · 1.71 KB
/
server.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
#from bottledaemon import daemon_run
from bottle import route, run, static_file, request, response, post, get, put, delete
try:
alarmset = set(line.strip() for line in open("alarms.conf", "r") if line.strip())
except:
file = open("alarms.conf", "w")
file.close
@route('/')
def time():
return static_file("main.html", root='.')
@route('/favicon.ico')
def time():
return static_file("favicon.ico", root='.')
@route('/icon.png')
def time():
return static_file("icon.png", root='.')
@route('/main.js')
def time():
return static_file("main.js", root='.')
@get('/favicon.ico')
def get_favicon():
return static_file('favicon.ico', root='.')
@get('/delete')
def makeAlarm():
if((request.query['time'] in alarmset)):
alarmset.remove(request.query['time'])
file = open("alarms.conf", "w")
file.write(str(alarmset).replace("'", '').replace("{", "").replace("}", "").replace(", ", "\n").replace("set()", ""))
file.close()
return {"success":True}
else:
return {"success":False}
@get('/alarms')
def getAlarm():
alarmdict = {}
for count, alarm in enumerate(alarmset):
alarmdict[count] = alarm
return alarmdict
#@post wasn't working so this is a work around
@get('/checkAlarm')
def checkAlarm():
if((request.query['time'] in alarmset) or (request.query['time'] == '')):
return {"exists":True}
else:
alarmset.add(request.query['time'])
file = open("alarms.conf", "w")
file.write(str(alarmset).replace("'", '').replace("{", "").replace("}", "").replace(", ", "\n"))
file.close()
return {"exists":False}
#if __name__ == "__main__":
# daemon_run()
run(host='0.0.0.0', port=8080, debug=True)