-
Notifications
You must be signed in to change notification settings - Fork 1
/
blinkfor.py
57 lines (45 loc) · 1.64 KB
/
blinkfor.py
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
51
52
53
54
55
56
57
import tweepy
import unicodedata
import time
import signal
import sys
import pymcu
import config
# I have a a file called config.py which has the 4 variables required for twitter in my git ignore
# I have a 5v buzzer from the arduino starter kit on digital pin 5 with no resistor :)
# I have an rgb led common ground on pins pwm: 1,2 and 3
class StreamListener( tweepy.StreamListener ):
def __init__( self ):
self.auth1 = tweepy.auth.OAuthHandler(config.consumer_key,config.consumer_secret)
self.auth1.set_access_token(config.access_token,config.access_token_secret)
self.api = tweepy.API(self.auth1)
self.board = pymcu.mcuModule()
self.board.pwmOff(1)
def on_status( self, status ):
val = unicodedata.normalize('NFD', status.text).encode('ascii','ignore')
print val
self.board.pwmOn(1)
for i in range(0, 255):
self.board.pwmDuty( 1, i )
self.board.freqOut(5,100,1319)
self.board.freqOut(5,100,2093)
self.board.freqOut(5,100,1047)
self.board.freqOut(5,100,1319)
self.board.freqOut(5,100,2093)
self.board.freqOut(5,100,1047)
for i in range(0, 255):
self.board.pwmDuty( 1, 255-i )
def exiting( self ):
self.board.pwmDuty( 1, 0 )
l = StreamListener()
def signal_handler(signal, frame):
l.exiting()
print 'Exiting...'
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
if len(sys.argv) > 1:
term = sys.argv[1]
else:
term = "tacos"
streamer = tweepy.Stream( auth=l.auth1, listener=l, timeout=3000000000 )
streamer.filter( follow=None, track=[term], async=False )