-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender.py
63 lines (39 loc) · 1.54 KB
/
sender.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
import requests
from random import randint
import time
import codecs
import os
import base64
def send_data(encoded_value):
data = '{"records":[{"key":"key1", "value":' + '"' + encoded_value + '"' + '}]}'
# data = encoded_value
# print(data)
response = requests.post('http://my-bridge-route-kafka-analytics.apps.adkadam-ocp1.shiftstack.com/topics/my-topic', headers=headers, data=data)
print(response.text)
headers = {
'content-type': 'application/vnd.kafka.json.v2+json',
}
path = "/home/adkadam/kafka-analytics/video/"
i = 0
for filename in os.listdir(path):
if i == 0:
if filename == "index.m3u8":
with open(os.path.join(path, filename), 'rb') as f:
playlist = f.read()
playlist_encode = base64.b64encode(playlist)
send_data(filename + str(playlist_encode, 'utf-8'))
i += 1
else:
if filename.startswith("segment"):
with open(os.path.join(path, filename), 'rb') as f:
segment = f.read()
segment_encode = base64.b64encode(segment)
send_data(filename + str(segment_encode, 'utf-8'))
i += 1
# response = requests.post('http://my-bridge-route-kafka-analytics.apps.adkadam-ocp1.shiftstack.com/topics/my-topic', headers=headers, data=data)
# print(response.text)
# video = open('webcam_output.mp4', 'rb')
# video_read = video.read()
# video_64_encode = base64.encodestring(video_read)
# print(video_64_encode)
# value = str(randint(0,100))