-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
47 lines (41 loc) · 1.32 KB
/
camera.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 datetime
import os
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from picamera import PiCamera, Color
from time import sleep
# file and directory settings
datetime = datetime.datetime.today()
capture_file_name = datetime.strftime('%Y%m%d%H%M%S') + '.jpg'
save_directory_path = 'LOCAL DIRECTORY PATH'
google_drive_folder_id = 'GOOGLE DRIVE FOLDER PATH'
# OAuth
gauth = GoogleAuth()
gauth.CommandLineAuth()
drive = GoogleDrive(gauth)
# take picture
camera = PiCamera()
camera.resolution = (860, 600)
camera.annotate_background = Color('black')
camera.annotate_foreground = Color('white')
camera.annotate_text = datetime.strftime('%Y/%m/%d %H:%M:%S')
sleep(5)
camera.capture(save_directory_path + capture_file_name)
if os.path.exists(save_directory_path + capture_file_name) :
# upload
f = drive.CreateFile({
'title': capture_file_name,
'mimeType': 'image/jpeg',
'parents': [{'kind': 'drive#fileLink', 'id':google_drive_folder_id}]
})
f.SetContentFile(save_directory_path + capture_file_name)
f.Upload()
#remove file
os.remove(save_directory_path + capture_file_name)
else :
f = drive.CreateFile({
'title': datetime.strftime('%Y%m%d%H%M%S') + '.txt',
'parents': [{'kind': 'drive#fileLink', 'id':google_drive_folder_id}]
})
f.SetContentString('file not found')
f.Upload()