Created
December 8, 2016 15:07
-
-
Save skorotkiewicz/f88bcd73159bde75ebc1ed7b66abeb70 to your computer and use it in GitHub Desktop.
My Raspberry Pi speech Tweets!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, re, time | |
from twython import TwythonStreamer | |
# Search terms | |
TERMS = '#yes' | |
# Twitter application authentication | |
APP_KEY = '' | |
APP_SECRET = '' | |
OAUTH_TOKEN = '' | |
OAUTH_TOKEN_SECRET = '' | |
# Setup callbacks from Twython Streamer | |
class BlinkyStreamer(TwythonStreamer): | |
def on_success(self, data): | |
if 'text' in data: | |
print data['text'].encode('utf-8') | |
tweet = data['text'].encode('utf-8') | |
tweetToSpeech = re.sub(r'\w+:\/{2}[\d\w-]+(\.[\d\w-]+)*(?:(?:\/[^\s/]*))*', '', tweet) # remove url | |
os.system('espeak -ven+f2 "{0}" --stdout | aplay 2>/dev/null >/dev/null'.format(tweetToSpeech)) #speech this! | |
stream = BlinkyStreamer(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) | |
stream.statuses.filter(track=TERMS) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment