-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicam.py
More file actions
executable file
·51 lines (39 loc) · 1.29 KB
/
picam.py
File metadata and controls
executable file
·51 lines (39 loc) · 1.29 KB
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
#!/usr/bin/env python
import os
import datetime
import subprocess
import upload
import daylight
import time
import logging
# setup some basic logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(levelname)s %(message)s',
filename='picam.log',
filemode='a')
def take_single_photo():
# Create unique filename based on time and date
utc_datetime = datetime.datetime.now()
nicetime = utc_datetime.strftime("%Y-%m-%d-%H%M")
# define the command
filename = nicetime + '.jpg'
# set the options to use
options = ['-w 500', # width 500px
'-h 500', # height 500px
'-q 80', # jpg quality to 80
'-rot 180'] # rotate image 180 degrees
cmd = 'raspistill -o ' + filename + ' ' + ' '.join(options)
print "Executing: ", cmd
logging.info('Executing in shell: %s' % cmd)
# how the hell does this run it!!?? you need to learn this!!!!!
pid = subprocess.call(cmd, shell=True)
time.sleep(10)
try:
upload.upload_image(filename)
except IOError:
print 'Upload failed. IOError.'
logging.debug('upload failed, IOError')
if daylight.is_daylight():
take_single_photo()
else:
logging.info('No photo taken, its after sunset.')