· 6 years ago · Aug 22, 2019, 12:00 PM
1import time
2import picamera
3import boto3
4from botocore.exceptions import NoCredentialsError
5import datetime
6import logging
7
8#Credentials given by AWS
9ACCESS_KEY = 'AKIAIQA7TLZ64JQD56EQ'
10SECRET_KEY = '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'
11
12
13def upload_to_aws(local_file, bucket, s3_file,i):
14 s3 = boto3.client('s3', aws_access_key_id=ACCESS_KEY,
15 aws_secret_access_key=SECRET_KEY)
16
17 try:
18 s3.upload_file(local_file, bucket, s3_file)
19 logging.info("Photo "+str(i)+" uploaded")
20 return True
21 except FileNotFoundError:
22 logging.info("File not found")
23 return False
24 except NoCredentialsError:
25 logging.info("No Credentials")
26 return False
27
28
29LOG_LEVEL = logging.INFO
30
31LOG_FILE = "/home/pi/Desktop/eagleye/log"
32
33LOG_FORMAT = "%(asctime)s %(levelname)s %(message)s"
34logging.basicConfig(filename=LOG_FILE, format=LOG_FORMAT, level=LOG_LEVEL)
35
36
37
38i = 0
39while True:
40 #Get time
41 timeNow = datetime.datetime.now()
42 #Check the time
43 if(timeNow.hour >= 7 and timeNow.hour < 20):
44 with picamera.PiCamera() as camera:
45 camera.resolution = (2592,1458)
46 camera.capture("lastCapture.jpg")
47 uploaded = upload_to_aws('lastCapture.jpg', 'arcelikphoto', 'capture'+str(i)+'.jpg',i)
48 i = i+1
49 time.sleep(60*5) # wait 5 minutes