Skip to content

Instantly share code, notes, and snippets.

@shogo82148
Created January 9, 2012 11:36
Show Gist options
  • Save shogo82148/1582593 to your computer and use it in GitHub Desktop.
Save shogo82148/1582593 to your computer and use it in GitHub Desktop.
A bot taking a picture in sl4a
#!/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()
droid.batteryStartMonitoring()
droid.startLocating()
consumer_key = 'Your Consumer Key'
consumer_secret = 'Your Consumer Secret'
access_key = 'Your Access Key'
access_secret = 'Your 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 = 30
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==1 or count%10==0:
try:
arg = {}
arg["status"] = "%d枚目パシャリ バッテリ状態:%d%%, %.1f度(%s)" % (
count,
droid.batteryGetLevel().result,
droid.batteryGetTemperature().result / 10.0,
time.strftime('%Y/%m/%d %H:%M:%S'))
try:
result = droid.getLastKnownLocation().result
arg["lat"] = result["latitude"]
arg["long"] = result["longitude"]
except:
pass
api.update_status(**arg)
except:
pass
except Exception, e:
api.update_status("エラーなう!err:%s (%s)" % (e, time.strftime('%Y/%m/%d %H:%M:%S')) )
return
time.sleep(0.5)
droid.batteryStopMonitoring()
droid.stopLocating()
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment