· 8 years ago · Dec 08, 2016, 03:56 PM
1import os, re, time
2from twython import TwythonStreamer
3
4
5# Search terms
6TERMS = '#yes'
7
8# Twitter application authentication
9APP_KEY = ''
10APP_SECRET = ''
11OAUTH_TOKEN = ''
12OAUTH_TOKEN_SECRET = ''
13
14# Setup callbacks from Twython Streamer
15class BlinkyStreamer(TwythonStreamer):
16 def on_success(self, data):
17 if 'text' in data:
18 print data['text'].encode('utf-8')
19 tweet = data['text'].encode('utf-8')
20 tweetToSpeech = re.sub(r'\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*', '', tweet) # remove url
21 os.system('espeak -ven+f2 "{0}" --stdout | aplay 2>/dev/null >/dev/null'.format(tweetToSpeech)) #speech this!
22
23stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
24stream.statuses.filter(track=TERMS)