From d57a5ca225797d399c99784a98ec041a68218c2c Mon Sep 17 00:00:00 2001 From: nbarry101 Date: Fri, 18 Aug 2017 22:24:05 +1000 Subject: [PATCH] Update timelapse.py Added check for interval length. Added minor diagnostic messages. --- timelapse.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/timelapse.py b/timelapse.py index 244eb26..65aae9c 100755 --- a/timelapse.py +++ b/timelapse.py @@ -4,10 +4,15 @@ from datetime import datetime from time import sleep import yaml +import sys config = yaml.safe_load(open("config.yml")) camera = PiCamera() +if config['interval'] < 2: + print "Inverval must be 2 or greater" + sys.exit() + def create_timestamped_dir(dir): try: os.makedirs(dir) @@ -17,8 +22,9 @@ def create_timestamped_dir(dir): try: # Create directory based on current timestamp. - dir = os.path.join(os.getcwd(), 'series-' + datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) + dir = os.path.join(os.getcwd(), config['directory'] + '/series-' + datetime.now().strftime('%Y-%m-%d_%H-%M-%S')) create_timestamped_dir(dir) + print "Directory: " + dir # Set camera resolution. if config['resolution']: @@ -45,7 +51,9 @@ def create_timestamped_dir(dir): # Capture images in series. for i in range(config['total_images']): camera.capture(dir + '/image{0:05d}.jpg'.format(i)) + print "Captured image " + str(i+1) + " of " + str(config['total_images']) sleep(config['interval'] - 2) + finally: camera.close()