-
Notifications
You must be signed in to change notification settings - Fork 0
/
daikinPushConfig.py
executable file
·59 lines (47 loc) · 1.69 KB
/
daikinPushConfig.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
#!/usr/bin/python
import sys, json, traceback, time, os
from daikinProtocol import *
def main(argv=None):
if argv is None:
argv = sys.argv
if len(argv) != 6:
return 1
fileHostCheck='./myhosts.json'
myHost=argv[1]
myHostId=argv[2]
myId=argv[3]
myUser=argv[4]
myPass=argv[5]
myHostDict={}
thisTime=int(time.time())
lifetime=3600*24
if os.path.exists(fileHostCheck):
with open(fileHostCheck, 'rb') as json_data:
try:
myHostDict = json.load(json_data)
except Exception as e:
print "failed when loading current host json file or parsing the json" + traceback.format_exc()
if myHost not in myHostDict:
myHostDict[myHost]={'timestamp':thisTime,'units':{},'user':myUser,'password':myPass,'hostId':myHostId}
else:
myHostDict[myHost]['timestamp']=thisTime
myHostDict[myHost]['user']=myUser
myHostDict[myHost]['password']=myPass
myHostDict[myHost]['hostId']=myHostId
if myId not in myHostDict[myHost]['units']:
myHostDict[myHost]['units'][myId]=thisTime
else:
myHostDict[myHost]['units'][myId]=thisTime
myNewHostDict={}
for host in list(myHostDict):
if myHostDict[host]['timestamp']<thisTime-(lifetime):
myHostDict.pop(host)
else:
for unit in list(myHostDict[host]['units']):
if myHostDict[host]['units'][unit]<thisTime-(lifetime):
myHostDict[host]['units'].pop(unit)
with open(fileHostCheck, 'wb') as fp:
json.dump(myHostDict, fp, indent=4, sort_keys=True)
print 1
if __name__ == "__main__":
sys.exit(main())