Last active
April 13, 2016 18:39
-
-
Save bennuttall/de3f3c32b4a20cd0b18ec7ab8dd5c070 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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