Skip to content

Commit

Permalink
Add an option to print the properties
Browse files Browse the repository at this point in the history
Call with --properties True
  • Loading branch information
deiger authored Apr 21, 2020
1 parent c3aed6e commit 7faec95
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions query_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
help='Device name to fetch data for. If not set, takes the first.')
arg_parser.add_argument('--config', required=True,
help='Config file to write to.')
arg_parser.add_argument('--properties', type=bool, default=False,
help='Fetch the properties for the device.')
args = arg_parser.parse_args()
logging_handler = logging.StreamHandler(stream=sys.stderr)
logging_handler.setFormatter(
Expand Down Expand Up @@ -208,6 +210,18 @@
except OSError:
pass # Not gzipped.
lanip = json.loads(resp_data)['lanip']
if args.properties:
conn.request('GET', '/apiv1/dsns/{}/properties.json'.format(dsn), headers=headers)
resp = conn.getresponse()
if resp.status != 200:
logging.error('Failed to get properties data from Hisense server: %r', resp)
sys.exit(1)
resp_data = resp.read()
try:
resp_data = gzip.decompress(resp_data)
except OSError:
pass # Not gzipped.
logging.info('Properties:\n%s', json.dumps(json.loads(resp_data), indent=2))
conn.close()
config = {
'lanip_key': lanip['lanip_key'],
Expand Down

0 comments on commit 7faec95

Please sign in to comment.