forked from ghalfacree/bash-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoorbell.py
More file actions
executable file
·28 lines (21 loc) · 817 Bytes
/
doorbell.py
File metadata and controls
executable file
·28 lines (21 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
# Tweeting doorbell for Raspberry Pi.
# Written by Gareth Halfacree <freelance@halfacree.co.uk>
import RPi.GPIO as GPIO
from twython import Twython
import datetime
api_token = 'InsertTokenHere'
api_secret = 'InsertSecretHere'
access_token = 'InsertOAuthTokenHere'
access_token_secret = 'InsertOAuthSecretHere'
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
twitter = Twython(api_token, api_secret, access_token, access_token_secret)
while True:
try:
print "Waiting for doorbell..."
GPIO.wait_for_edge(23, GPIO.FALLING)
print "Doorbell detected, sending direct message."
twitter.send_direct_message(screen_name="ghalfacree", text="DING-DONG at %s" %datetime.datetime.now())
except KeyboardInterrupt:
GPIO.cleanup()