Android Python Timelapse

So It’s been a little while since I messed around with android scripting, but I just finished a fun script that someone may find useful. I created a small timelapse script that allows the user to choose the interval and the folder where it will save the pictures (on the sdcard).

Choose the interval to take pictures, in minutes. Default choices are 1, 5, 10, 30, 60 minute intervals, or choose custom and enter your own value

Choose the folder in which to save the pictures

Let it do its thing!

You can grab the file here: timelapse.py or copy and paste the code below:


import android, time, os

droid = android.Android()

def titleAlert():
title = 'Android Python Timelapse'
message = 'Welcome to Android Python Timelapse. In the following dialogs, you will be asked to choose your interval and the location where you would like your pictures saved. Enjoy! Questions or comments? Please send to Support@SubmergedSpaceman.com'
droid.dialogCreateAlert(title, message)
droid.dialogSetPositiveButtonText('Continue')
droid.dialogShow()
response = droid.dialogGetResponse().result
return response['which'] == 'positive'

def chooseInterval():
title = 'Please choose your picture interval in minutes. To use a different value, choose Custom'
droid.dialogCreateAlert(title)
droid.dialogSetItems(['1', '5', '10','30','60','Custom'])
droid.dialogShow()
response = droid.dialogGetResponse().result['item']

if response == 0:
timer = 1
elif response == 1:
timer = 5
elif response == 2:
timer = 10
elif response == 3:
timer = 30
elif response == 4:
timer = 60
elif response == 5:
timer = droid.dialogGetInput("please enter your interval in minutes").result
timer = float(timer)
print "interval is: "+str(timer) +" minutes"
return timer

def chooseFolder():
title = 'Please choose where you would like to store your pictures'
captureTime = time.strftime("%Y-%m-%d--%H-%M-%S", time.localtime())
droid.dialogCreateAlert(title)
droid.dialogSetItems(['/sdcard/YYYY-MM-DD', '/sdcard/timelapse', 'Custom'])
droid.dialogShow()
response = droid.dialogGetResponse().result['item']

if response == 0:
folderStr = captureTime
elif response == 1:
folderStr = "timelapse"
elif response == 2:
folderStr = droid.dialogGetInput("please enter the name of the folder you would like to create: /sdcard/").result

print "folder set to: /sdcard/"+folderStr
return folderStr

def takePics(picfolder="timelapse", lapse=30):
loopvar = 'true'

while loopvar == 'true':
captureTime = time.strftime("%Y-%m-%d--%H-%M-%S", time.localtime())
captureLocation = '/sdcard/'+picFolder+"/"+str(captureTime)+'.jpg'
print "picture taken: "+captureLocation
droid.cameraCapturePicture(captureLocation,True)
interval = lapse * 60
time.sleep(interval)

titleAlert()
lapse = chooseInterval()
picFolder = chooseFolder()
os.system("mkdir /sdcard/"+picFolder)
takePics(picFolder,lapse)

And here is the video I made after letting the script run for about 4 days. There was some sort of opening ceremony happening by our apartment, but we were out of town for the weekend. Glad I got it all on film! (It’s pretty slow going at the start, skip to about 1:40 where things start to get going)

check out my other SL4A script:
http://www.submergedspaceman.com/blog/2010/02/16/android-scripting-environment-is-incredible-part-i/

And my new cell stand in the shop!
http://www.submergedspaceman.com/blog/2010/09/25/universal-cellphone-stand/
(you can get it from Ponoko or Etsy from that link as well)

Universal Cellphone Stand

stand with phone
Hello! I’ve just added a new page on my site; the shop! My first product is one I recently created using the great laser cutting website Ponoko.com. It’s a stand for phones. I thought about it a while ago and decided to try out the Ponoko service. everything worked great! Check it out here at Ponoko.com or on Etsy.com here You can purchase it right at my shop or either of those websites (they all use paypal, so it’s the same to me) Go get one!