###astro pi bird###
###Coded by TeCoEd###

import sys, subprocess, urllib, time, tweepy, os

# == 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= 'xxxxxx'
consumer_secret= 'xxxxxxxxxxxxxxxxxxxx'

# 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= 'xxxxxxxxxxxxxxxxxxxxxx'
access_token_secret= 'xxxxxxxxxxxxxxxxxxxxx'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

class Astro_Bird(tweepy.StreamListener):
    def on_status(self, tweet):

        tweet_to_check = tweet.text
        print (tweet_to_check)

        if tweet_to_check.find("@astro_timpeake") >= 0:
            print tweet_to_check
            print ("found a Tim Peake Tweet")
            #play mp3 sound
            os.system('mpg321 bird.mp3 &')
            
            
stream = tweepy.Stream(auth, Astro_Bird())

while True:
    stream.userstream()
        

