-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpi_code.py
More file actions
51 lines (35 loc) · 1.19 KB
/
pi_code.py
File metadata and controls
51 lines (35 loc) · 1.19 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import time
import RPi.GPIO as GPIO
from twython import TwythonStreamer
# Search terms - Use a unique hashtag here eg. '#ISSoverheadMyStreet'
TERMS = '#ISSoverhead'
# Setup GPIO as output
GPIO.setmode(GPIO.BOARD)
# GPIO pin number of LED
LED = 36
GPIO.setup(LED, GPIO.OUT)
GPIO.output(LED, GPIO.LOW)
# Twitter application authentication
APP_KEY = 'YourTwitterInfoHere'
APP_SECRET = 'YourTwitterInfoHere'
OAUTH_TOKEN = 'YourTwitterInfoHere'
OAUTH_TOKEN_SECRET = 'YourTwitterInfoHere'
# Setup callbacks from Twython Streamer
class BlinkyStreamer(TwythonStreamer):
def on_success(self, data):
if 'text' in data:
print data['text'].encode('utf-8')
print
i=0
while i < 20:
GPIO.output(LED,1)
time.sleep(0.5)
GPIO.output(LED,0)
time.sleep(0.5)
i = i + 1
# Create streamer
try:
stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(track=TERMS)
except KeyboardInterrupt:
GPIO.cleanup()