Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active April 13, 2016 18:39
Show Gist options
  • Select an option

  • Save bennuttall/de3f3c32b4a20cd0b18ec7ab8dd5c070 to your computer and use it in GitHub Desktop.

Select an option

Save bennuttall/de3f3c32b4a20cd0b18ec7ab8dd5c070 to your computer and use it in GitHub Desktop.
from twython import Twython
from picamera import PiCamera
from time import sleep
from datetime import datetime
from gpiozero import Button, MotionSensor
from auth import (
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
twitter = Twython(
consumer_key,
consumer_secret,
access_token,
access_token_secret
)
def tweet_photo():
with open(photo_path, 'rb') as photo:
twitter.update_status_with_media(media=photo)
pir = MotionSensor(14)
yes_button = Button(2)
no_button = Button(3)
camera = PiCamera()
while True:
yes_button.when_pressed = None
pir.wait_for_motion()
timestamp = datetime.now().isoformat()
photo_path = '/home/pi/photos/%s.jpg' % timestamp
sleep(3)
camera.capture(photo_path)
yes_button.when_pressed = tweet_photo
while True:
if no_button.is_pressed:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment