-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlarmStorage.py
43 lines (32 loc) · 1.04 KB
/
AlarmStorage.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
import json
import time
def SaveAlarmsToJson(data):
# get existing alarms
jsonData = ReturnAlarmsInJson()
# print jsonData
# either over right data for that key, or add it to the json
jsonData.update(data)
# print jsonData
# save the results back to the json file.
with open('static/assets/js/alarms.json', 'w') as fp:
json.dump(jsonData, fp)
return '1'
def DeleteAlarmByID(id):
jsonData = ReturnAlarmsInJson()
if str(id) in jsonData.keys():
del jsonData[str(id)]
with open('static/assets/js/alarms.json', 'w') as fp:
json.dump(jsonData, fp)
return '1'
else:
return '0'
def ReturnAlarmsInJson():
with open('static/assets/js/alarms.json', 'r') as fp:
return json.load(fp)
# WTF
# data = {}
# key = str(datetime.datetime.now().hour * 60 + datetime.datetime.now().minute)
# data = {key: {'timeInMinutes': key, 'isActive': 1, 'days': [0, 1, 1, 1, 1, 1, 0]}}
# SaveAlarmsToJson(data)
# DeleteAlarmByID(586)
# print ReturnAlarmsInJson()