|
@@ -46,7 +46,7 @@ def get_redis_token():
|
|
|
if token_val is not None:
|
|
|
redis_set_with_time(redis_key, token_val, 300)
|
|
|
|
|
|
- print('token:', token_val)
|
|
|
+ # print('token:', token_val)
|
|
|
return token_val
|
|
|
|
|
|
# 2.1获取区域
|
|
@@ -64,19 +64,22 @@ def get_redis_token():
|
|
|
}
|
|
|
'''
|
|
|
def get_region():
|
|
|
- token = get_token()
|
|
|
+ token = get_redis_token()
|
|
|
headers = {
|
|
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
|
"Authorization": "Bearer " + token
|
|
|
}
|
|
|
api_url = API_ROOT + "/region"
|
|
|
response = requests.get(url=api_url, headers=headers, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['region']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
# 2.2获取区域组节点
|
|
|
'''
|
|
@@ -100,7 +103,7 @@ def get_region():
|
|
|
}
|
|
|
}
|
|
|
'''
|
|
|
-def get_group(region_id: str):
|
|
|
+def get_group(region_id: str, parent_id: str = ''):
|
|
|
token = get_redis_token()
|
|
|
headers = {
|
|
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
@@ -109,14 +112,22 @@ def get_group(region_id: str):
|
|
|
params = {
|
|
|
"region_id": region_id
|
|
|
}
|
|
|
+
|
|
|
+ if parent_id != '':
|
|
|
+ params = {
|
|
|
+ "parent_id": parent_id
|
|
|
+ }
|
|
|
api_url = API_ROOT + "/group"
|
|
|
response = requests.get(url=api_url, headers=headers, params=params, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['group']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
# 2.3根据名称搜索区域下所有的节点
|
|
|
'''
|
|
@@ -222,12 +233,15 @@ def get_search_region(region_name: str):
|
|
|
}
|
|
|
api_url = API_ROOT + "/search/region"
|
|
|
response = requests.get(url=api_url, headers=headers, params=params, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
# 2.4搜索范围内的通道信息及直播流地址
|
|
|
'''
|
|
@@ -276,12 +290,15 @@ def get_search_live_location(center_lat: float, center_lng: float, point_lat: fl
|
|
|
}
|
|
|
api_url = API_ROOT + "/search/live-location"
|
|
|
response = requests.get(url=api_url, headers=headers, params=params, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['channel']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
|
|
|
# 3.1获取设备
|
|
@@ -330,12 +347,15 @@ def get_group_device(group_id: str, dev_type: dict = None, status: int = -1):
|
|
|
api_url = API_ROOT + "/group/" + group_id + "/device"
|
|
|
print('get_group_device:', api_url)
|
|
|
response = requests.get(url=api_url, headers=headers, params=params, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['device']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
# 4.1 获取通道
|
|
|
'''
|
|
@@ -370,12 +390,15 @@ def get_device_channel(device_id: str, status: int = -1):
|
|
|
|
|
|
api_url = API_ROOT + "/device/" + device_id + "/channel"
|
|
|
response = requests.get(url=api_url, headers=headers, params=params, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['channel']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
|
|
|
# 4.2 获取所有通道
|
|
@@ -423,12 +446,15 @@ def get_channel_all(status: int = -1, gpsonly: int = -1):
|
|
|
|
|
|
api_url = API_ROOT + "/channel/all"
|
|
|
response = requests.get(url=api_url, headers=headers, params=params, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['channel']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
# 5.1 获取直播流
|
|
|
'''
|
|
@@ -448,12 +474,15 @@ def get_live_streaming(channel_id: str):
|
|
|
}
|
|
|
api_url = API_ROOT + "/live/streaming/" + channel_id
|
|
|
response = requests.get(url=api_url, headers=headers, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['live_url']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
# 5.2云台控制
|
|
|
# 没用
|
|
@@ -476,12 +505,15 @@ def get_live_playing(channel_id: str):
|
|
|
}
|
|
|
api_url = API_ROOT + "/live/playing/" + channel_id
|
|
|
response = requests.get(url=api_url, headers=headers, timeout=15)
|
|
|
- print(response.text)
|
|
|
+
|
|
|
if response.status_code == 200:
|
|
|
result = response.json()
|
|
|
if result['code'] == 0:
|
|
|
data = result['data']
|
|
|
return data['play_url']
|
|
|
+ else:
|
|
|
+ print(response.text)
|
|
|
+
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
get_region()
|