# -*- coding: utf-8 -*-
import time
import picamera
from datetime import datetime, timedelta
def ask_delay(ask_delay,retries,complaint):
while True:
global delay
global start
start =False
delay = raw_input(ask_delay)
if delay.isdigit():
#判断是否为数字
delay = int(delay)
start =True
break
retries = retries - 1
if retries < 0:
raise IOError('run again')
print complaint
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
while True:
global anwser
#全局变量
anwser = raw_input(prompt)
if anwser in ('y', 'ye', 'yes'):
#print anwser#
ask_delay('How many delay do you want?',4,'Please input number!')
break
if anwser in ('n', 'no', 'nop', 'nope'):
print anwser
break
retries = retries - 1
if retries < 0:
raise IOError('run again')
print complaint
def take_pictures():
if start == True:
with picamera.PiCamera() as camera:
#camera.start_preview()
time.sleep(2)
for filename in camera.capture_continuous('img{counter:03d}.jpg'):
print('Captured %s' % filename)
print("taking picture per %r sec >>>>>>" %delay)
time.sleep(delay) # wait delays
ask_ok('Do you want to take timelapse pictures?', 4, 'Come on, only yes or no!')
take_pictures()
###TOP