-
Notifications
You must be signed in to change notification settings - Fork 0
/
short-sample-request.py
executable file
·72 lines (62 loc) · 1.92 KB
/
short-sample-request.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
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import requests
import json, jsonpickle
import os
import sys
import base64
import glob
#
# Use localhost & port 5001 if not specified by environment variable REST
#
REST = os.getenv("REST") or "localhost:5001"
##
# The following routine makes a JSON REST query of the specified type
# and if a successful JSON reply is made, it pretty-prints the reply
##
def mkReq(reqmethod, endpoint, data, verbose=True):
print(f"Response to http://{REST}/{endpoint} request is {type(data)}")
jsonData = jsonpickle.encode(data)
if verbose and data != None:
print(f"Make request http://{REST}/{endpoint} with json {data.keys()}")
print(f"mp4 is of type {type(data['mp4'])} and length {len(data['mp4'])} ")
response = reqmethod(f"http://{REST}/{endpoint}", data=jsonData,
headers={'Content-type': 'application/json'})
if response.status_code == 200:
jsonResponse = json.dumps(response.json(), indent=4, sort_keys=True)
print(jsonResponse)
return
else:
print(
f"response code is {response.status_code}, raw response is {response.text}")
return response.text
for mp4 in glob.glob("worker/*mp4"):
print(f"Separate data/{mp4}")
mkReq(requests.post, "apiv1/operation",
data={
"mp4": base64.b64encode( open(mp4, "rb").read() ).decode('utf-8'),
"operations":[
{
'operation':'trim',
'operation_args':{
'start_time': 1,
'end_time': 5
}
},
{
'operation':'hflip',
'operation_args':{}
}
]
},
verbose=True
)
sys.exit(0)
## TODO
'''
1. GKE
3. Video
4. PDF
5. React and Server Sent Events (Aspirational)
6. Not using NATS for ACK are we?
7. Work out on extracting audio
'''