-
Notifications
You must be signed in to change notification settings - Fork 4
/
solarWeb.py
executable file
·55 lines (45 loc) · 1.7 KB
/
solarWeb.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
#!/usr/bin/env python3
import requests
MAXTRYS = 10
class SolarDataWeb:
def __init__(self):
self.webdata_now_p = 0
self.webdata_today_e = 0.0
self.webdata_total_e = 0.0
def getWebWatt(url, user, password):
try:
sdw = SolarDataWeb()
data = requests.get("http://{}/status.html".format(url), auth=(user, password), timeout=2)
for zeile in data.text.split('\n'):
if 'var webdata_now_p' in zeile:
left_texter = zeile.find('"', 0, len(zeile)) + 1
right_texter = zeile.find('"', left_texter, len(zeile))
sdw.webdata_now_p = int(zeile[left_texter:right_texter])
if 'var webdata_today_e' in zeile:
left_texter = zeile.find('"', 0, len(zeile)) + 1
right_texter = zeile.find('"', left_texter, len(zeile))
sdw.webdata_today_e = float(zeile[left_texter:right_texter])
if 'var webdata_total_e' in zeile:
left_texter = zeile.find('"', 0, len(zeile)) + 1
right_texter = zeile.find('"', left_texter, len(zeile))
sdw.webdata_total_e = float(zeile[left_texter:right_texter])
return sdw
except Exception:
return None
def doTryWebWatt(url, user, password):
i = 1
while i < MAXTRYS:
i += 1
wert = getWebWatt(url, user, password)
if (wert != None):
return wert
return None
# Just for local testing
if __name__ == '__main__':
sd = doTryWebWatt("192.168.2.15", "admin", "admin")
if (sd != None):
print(sd.webdata_now_p)
print(sd.webdata_today_e)
print(sd.webdata_total_e)
else:
print("Keine Verbindung")