· 6 years ago · Jul 30, 2019, 06:44 AM
1import requests
2import time
3
4import boto3
5from botocore.exceptions import NoCredentialsError
6
7
8def upload_to_aws(local_file, bucket, s3_file):
9 s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
10 aws_secret_access_key=SECRET_KEY)
11
12 try:
13 s3.upload_file(local_file, bucket, s3_file)
14 print("Upload Successful")
15 return True
16 except FileNotFoundError:
17 print("The file was not found")
18 return False
19 except NoCredentialsError:
20 print("Credentials not available")
21 return False
22
23
24
25
26url = 'http://10.155.10.141/jpg'
27
28
29ACCESS_KEY = 'AKIAIQA7TLZ64JQD56EQ'
30SECRET_KEY = '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'
31
32
33i = 0
34while True:
35 r = requests.get(url, allow_redirects=True)
36 open('image'+str(i)+'.jpg', 'wb').write(r.content)
37 uploaded = upload_to_aws('image'+str(i)+'.jpg', 'arcelikphoto', 'image.jpg')
38 time.sleep(1*60) # wait 5 minutes
39 i = i+1