SL4Aでインターバル撮影してみる

よくあるインターバル撮影。それだけじゃつまらないからツイッターつぶやき機能をつけてみたよ!これでちゃんと動作しているかをリモートで確認できます。
tweepyをつかっているので、別途インストールが必要。

先頭のwakeLockAcquirePartialはCPUスリープ防止。これが無いと省エネ設定になっていると撮影が途中で止まってしまう。releaseしてないけど終了時に勝手にリリースされる・・・よね?

#!/usr/local/bin/python
# -*- coding: utf-8 -*-

import tweepy
import codecs
import sys
import threading
import time
import android

droid = android.Android()

def main():
    droid.wakeLockAcquirePartial()
    consumer_key = 'Your Consumer Key'
    consumer_secret = 'Your Secret Key'
    access_key = 'Access Key'
    access_secret = 'Access Secret'

    auth = tweepy.OAuthHandler(consumer_key=consumer_key, consumer_secret=consumer_secret)
    auth.set_access_token(access_key, access_secret)
    api = tweepy.API(auth)

    count = 0
    interval = 10
    api.update_status("撮影開始なう(%s)" % time.strftime('%Y/%m/%d %H:%M:%S'))
    take_time = time.time() + interval
    while True:
        try:
            t = time.time()
            if t>=take_time:
                take_time = t + interval
                droid.cameraCapturePicture("/sdcard/DCIM/sl4a/sl4a%04d.jpg" % count)
                count += 1
                if count%10==0:
                    api.update_status("%d枚目パシャリ(%s)" % (count, time.strftime('%Y/%m/%d %H:%M:%S')))
        except:
            api.update_status("エラーなう!(%s)" % time.strftime('%Y/%m/%d %H:%M:%S'))
            return
        time.sleep(0.5)