|
@@ -1,6 +1,5 @@
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
@@ -10,9 +9,21 @@ import sys
|
|
|
import json
|
|
|
import requests
|
|
|
|
|
|
-address = sys.argv[1]
|
|
|
-response = requests.get('http://{}/api/v1/data'.format(address))
|
|
|
-parsed = response.json()
|
|
|
+def main():
|
|
|
+ args = sys.argv[1:]
|
|
|
+ if len(args) < 1:
|
|
|
+ print("Usage: script.py IP or FQDN")
|
|
|
+ sys.exit(1)
|
|
|
+
|
|
|
+ address = args[0]
|
|
|
+ try:
|
|
|
+ response = requests.get('http://{}/api/v1/data'.format(address))
|
|
|
+ except requests.exceptions.RequestException as e:
|
|
|
+ raise SystemExit(e)
|
|
|
+
|
|
|
+ parsed = response.json()
|
|
|
+ print('<<<local>>>')
|
|
|
+ iterate_json(parsed)
|
|
|
|
|
|
|
|
|
|
|
@@ -24,7 +35,7 @@ def iterate_json(json_obj):
|
|
|
else:
|
|
|
if key.startswith("active"):
|
|
|
if key.endswith("_w"):
|
|
|
- print(f"P {key} watt={value};2100;2200;2300;0;2500 Current Watts:{value}")
|
|
|
+ print(f"P {key} Power={value};2100;2200;2300;0;2500 Current Watts:{value}")
|
|
|
if key.endswith("_v"):
|
|
|
print(f"P {key} volt={value};252;253;260;0;300 Current Volts:{value}")
|
|
|
if key.endswith("_a"):
|
|
@@ -32,11 +43,11 @@ def iterate_json(json_obj):
|
|
|
if key.endswith("tariff"):
|
|
|
print(f"P {key} tariff={value};;;;; Current Tariff:{value}")
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-print('<<<local>>>')
|
|
|
-iterate_json(parsed)
|
|
|
+if __name__ == "__main__":
|
|
|
+ main()
|