· 8 years ago · Dec 13, 2016, 05:28 AM
1import time
2import RPi.GPIO as GPIO
3from twython import TwythonStreamer
4
5# Search terms
6TERMS = '#yes'
7
8# GPIO pin number of LED
9LED = 22
10
11# Twitter application authentication
12APP_KEY = 'erRilYZd8UzsXEFycmg'
13APP_SECRET = 'Yt0fGlNvCyr1sFaC6ymdNhphHchaWbz0ECdotEXIQQ'
14OAUTH_TOKEN = '1969690717-6a2RgVPXanSBaAjuie7EmUWZh78me8UZ6UxcM8V'
15OAUTH_TOKEN_SECRET = 'UIrYV2XbYZC3vHzer6ZxIDwqVa0VvynQLDJYnSQV0R3xt'
16
17# Setup callbacks from Twython Streamer
18class BlinkyStreamer(TwythonStreamer):
19 def on_success(self, data):
20 if 'text' in data:
21 print data['text'].encode('utf-8')
22 print
23 GPIO.output(LED, GPIO.HIGH)
24 time.sleep(0.5)
25 GPIO.output(LED, GPIO.LOW)
26
27# Setup GPIO as output
28GPIO.setmode(GPIO.BOARD)
29GPIO.setup(LED, GPIO.OUT)
30GPIO.output(LED, GPIO.LOW)
31
32# Create streamer
33try:
34 stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
35 stream.statuses.filter(track=TERMS)
36except KeyboardInterrupt:
37 GPIO.cleanup()