-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapex.py
executable file
·48 lines (42 loc) · 1.34 KB
/
apex.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
#!/usr/bin/python
import requests
import xmltodict
import time
skip = ['Salt', 'Email2Alm_I9']
while True:
try:
r = requests.get('http://xapex.x/cgi-bin/status.xml', timeout=2)
except:
print("timeout")
time.sleep(8)
continue
d = xmltodict.parse(r.text, namespaces=True)
with open('/home/xero/misc/documents/apex', 'r+') as out:
line ='Current Apex Status:\n'+d['status']['date']
print(line)
out.write(line+'\n')
for probe in d['status']['probes']['probe']:
if probe['name'] in skip or probe['name'].endswith('A') or probe['name'].startswith('Unused'):
continue
if probe['name'].endswith('W'):
value = probe['value'] + ' watts'
else:
value = probe['value']
line = '%s: %s' % (probe['name'], value)
print(line)
out.write(line+'\n')
for outlet in d['status']['outlets']['outlet']:
if outlet['name'] in skip or outlet['name'].startswith('VarSpd') or outlet['name'].startswith('Snd') or outlet['name'].startswith('Unused'):
continue
if outlet['state'] == 'AON':
state = 'AUTO ON'
elif outlet['state'] == 'AOF':
state = 'AUTO OFF'
else:
state = outlet['state']
line = '%s: %s' % (outlet['name'], state)
print(line)
out.write(line+'\n')
out.truncate()
print()
time.sleep(5)