###TeCoEd and a T-REX:-) + Aaron Hill
## An improved version that streams Tweets and now Boris ROARS
## on instances of ROAR in the timeline
 
import sys, subprocess, urllib, time, tweepy
import piface.pfio as pfio
pfio.init()
 
# == OAuth Authentication ==
#
# This mode of authentication is the new preferred way
# of authenticating with Twitter.
 
# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key= 'XXXXXXXXXXXXXXXXXXXXXXXXX'
consumer_secret= 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' 
 
# The access tokens can be found on your applications's Details
# page located at https://dev.twitter.com/apps (located 
# under "Your access token")
access_token= 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
access_token_secret= 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
 
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
 
api = tweepy.API(auth)
 
print api.me()
 
class DinoStreamListener(tweepy.StreamListener):
    def on_status(self, tweet):
        if tweet.text == "@dan_aldred ROAR": #Phrase when the dino respsonds to             pfio.digital_write(7, 1)
            print tweet.text
            pfio.digital_write(7, 1)
            time.sleep(10)
            print tweet.user.screen_name + " Made Boris ROAR"
            
        else:
            print tweet.text
            pfio.digital_write(7, 0)
            print tweet.user.screen_name
            time.sleep(60)
    
stream = tweepy.Stream(auth, DinoStreamListener())
 
try:
    stream.userstream()
except KeyboardInterrupt:
    print "Exiting!"
    stream.disconnect()
