-
Notifications
You must be signed in to change notification settings - Fork 3
/
collect_json.py
executable file
·43 lines (36 loc) · 1.68 KB
/
collect_json.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
#!/usr/bin/env python
'''
Python script to get json data from Hive
python get_hive_json.py [-h] username password
'''
import requests
import json
import sys
import argparse
from pprint import pprint
parser = argparse.ArgumentParser(description='Get Hive JSON data.')
parser.add_argument('username', help='Hive Username')
parser.add_argument('password', help='Hive Password')
args = parser.parse_args()
requests.packages.urllib3.disable_warnings()
# log on to Hive
payload = {'sessions':[{'username':args.username, 'password':args.password}]}
headers = {'Content-Type': 'application/vnd.alertme.zoo-6.1+json', 'Accept': 'application/vnd.alertme.zoo-6.2+json', 'X-AlertMe-Client': 'Hive Web Dashboard'}
url = 'https://api.prod.bgchprod.info:443/omnia/auth/sessions'
r = requests.post(url, headers=headers, data=json.dumps(payload), verify=False)
if "errors" in r.json():
pprint(r.json())
sys.exit(1)
sessionId = r.json()["sessions"][0]['sessionId']
headers = {'Content-Type': 'application/vnd.alertme.zoo-6.2+json', 'Accept': 'application/vnd.alertme.zoo-6.2+json', \
'X-AlertMe-Client': 'swagger', 'X-Omnia-Access-Token': sessionId}
url = 'https://api.prod.bgchprod.info:443/omnia/nodes'
r = requests.get(url, headers=headers, verify=False)
# Find thermostat node
#print(r.json()["nodes"])
print(json.dumps(r.json(),sort_keys=True, indent=4))
# log out from Hive
headers = {'Content-Type': 'application/vnd.alertme.zoo-6.1+json', 'Accept': 'application/vnd.alertme.zoo-6.2+json', \
'X-AlertMe-Client': 'Hive Web Dashboard', 'X-Omnia-Access-Token': sessionId}
url = 'https://api.prod.bgchprod.info:443/omnia/auth/sessions/' + sessionId
r = requests.delete(url, headers=headers, verify=False)