-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcameras_create_custom_event.py
59 lines (44 loc) · 1.52 KB
/
cameras_create_custom_event.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
50
51
52
53
54
55
56
57
58
59
"""Test for resize images from VXG Server use opencv."""
import io
import os
import sys
import requests
import subprocess
import base64
import json
import shlex
import argparse
from datetime import datetime, timedelta
def create_custom_event(token: str, cam_id: int, custom_event_name: str):
"""Get image URL from VXG Cloud."""
try:
headers = {
'accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Acc %s' % token,
}
url = "https://web.skyvr.videoexpertsgroup.com/api/v2/cameras/%d/event_processing/events/"%(cam_id)
data = "{ \"name\": \"%s\", \"notify\": true}"%(custom_event_name);
print("---\ndata: %s\n---"%(data))
resp = requests.post(url=url, headers=headers, data = data, timeout=10).json()
print(resp)
return resp.get('urls', [])
except Exception as e:
print(e)
return []
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--token', help='Access token', required=True)
parser.add_argument('-e', '--event_name', help='Custom event name', default='motion_detection')
param = parser.parse_args()
token_json=''
try:
token = base64.b64decode(param.token)
token_json = json.loads(token)
except Exception:
print("Invalid access token")
sys.exit(1)
cam_id = token_json["camid"]
create_custom_event(param.token, cam_id, param.event_name)
if __name__ == '__main__':
main()