-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadmin_api_get_meta.py
49 lines (42 loc) · 1.47 KB
/
admin_api_get_meta.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
43
44
45
46
47
48
49
import argparse
import requests
import sys
import json
# Function for executing HTTP request
def admin_api_get_meta(serv_key, id_channel):
# HTTP header. Indicates the MIME document type (json) as well as the authorization key
headers = {
'accept': 'application/json',
'Authorization': 'LKey ' + serv_key,
}
address = 'https://web.skyvr.videoexpertsgroup.com:443/api/v3/channels/%s/meta/' % id_channel # End point
# Exceptions block.
try:
response = requests.get(address, headers=headers, timeout=15)
except requests.exceptions.RequestException as e:
print (e)
sys.exit(1)
return response.status_code, response.text # The function returns the status and the return data
# Parsing of the command line
parser = argparse.ArgumentParser()
parser.add_argument('-serv_key', '--serv_key', help = 'Server key', required=True)
parser.add_argument('-id_channel', '--id_channel', help = 'Channel id', required=True, type=int)
try:
param = parser.parse_args()
except IOError as msg:
parser.error(str(msg))
# Function call
code, data = admin_api_get_meta(param.serv_key, str(param.id_channel))
# Status of the HTTP request
print ('Request completed. HTTP status code: ' + str(code)+'\n')
# Вывод полученных данных
try:
data_json = json.loads(data)
except Exception:
pass
print ("Channel meta info:")
try:
for obj in data_json["objects"]:
print (obj)
except Exception:
print ("-------------")