X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=home%2Fportalmonitor.py;h=1316b2f6807d50233c13f511c81767d56e040091;hb=795e2766cb2798789364c5933153274ad1b27818;hp=13a7b98ba55207ad7861809264eea7857cad400f;hpb=f3cde97f6e775414519f87835c3a2cdddfcf2293;p=sven%2Fscripts.git diff --git a/home/portalmonitor.py b/home/portalmonitor.py index 13a7b98..1316b2f 100755 --- a/home/portalmonitor.py +++ b/home/portalmonitor.py @@ -39,22 +39,26 @@ def isDaylight(lat, lon, toleranceSeconds): def getCurrentPower(userName, password, stationId): with requests.Session() as s: - r = s.post('https://www.envertecportal.com/apiaccount/login', - data={ - 'userName': userName, - 'pwd': password - }, - timeout=(10, 30)) - - r = s.post('https://www.envertecportal.com/ApiStations/getStationInfo', - data={ - 'stationId': stationId - }, - timeout=(10, 60)).json() - power = r['Data']['Power'] - - r = s.post('https://www.envertecportal.com/apiAccount/Logout', - timeout=(10, 30)) + try: + r = s.post('https://www.envertecportal.com/apiaccount/login', + data={ + 'userName': userName, + 'pwd': password + }, + timeout=(10, 30)) + + r = s.post( + 'https://www.envertecportal.com/ApiStations/getStationInfo', + data={ + 'stationId': stationId + }, + timeout=(10, 60)).json() + power = r['Data']['Power'] + + r = s.post('https://www.envertecportal.com/apiAccount/Logout', + timeout=(10, 30)) + except requests.exceptions.RequestException as e: + raise SystemExit(e) return float(power) @@ -71,7 +75,7 @@ if isDaylight(conf['config'].getfloat('lat'), conf['config'].getfloat('lon'), conf['config']['stationId']) if options.printStatus: - print('Current Power: ' + str(currentPower)) + print(f"Current Power: {currentPower}") if currentPower == 0: print('Error: Power dropped to 0 but we should have daylight!')