-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinesis_base64_encode.py
47 lines (39 loc) · 1.25 KB
/
kinesis_base64_encode.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
import boto3
import json
import base64
my_stream_name = 'new_try'
kinesis_client = boto3.client('kinesis', region_name='us-east-1')
def put_to_stream(thing_id,b64,count):
payload = {
'image_id': str(b64),
#'image_id': count
}
#print (payload)
put_response = kinesis_client.put_record(
StreamName=my_stream_name,
Data=json.dumps(payload),
PartitionKey=thing_id)
print (put_response)
def main():
image_id = 0
while True:
thing_id = 'CAMERA-001'
with open("/Users/ashukumar/Desktop/Standard/ASHUimgs/"+str(image_id)+".jpg","rb") as imageFile:
stream = base64.b64encode(imageFile.read())
print(stream)
t=str(stream)
t=t[2:-1]
print('\n')
print(t)
fh = open("/Users/ashukumar/Desktop/kin/" + str(image_id) + ".jpg", "wb")
fh.write(base64.b64decode(t))
fh.close()
#print("/Users/ashukumar/Desktop/Standard/ASHUimgs/" + str(image_id) + ".jpg")
#print(stream)
#put_to_stream(thing_id,stream,image_id)
image_id+=1
print(image_id)
if image_id>1:
break
if __name__=='__main__' :
main()