How to use the tweepy.Stream function in tweepy

To help you get started, we’ve selected a few tweepy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jmortega / osint_tools_security_auditing / twitter / osint_twitter.py View on Github external
def streamAPI(auth):
   # Instantiate our listener
   l = StreamListener()
   # Instantiate the streamer with OAuth object and the listener
   streamer = tweepy.Stream(auth=auth, listener=l)
   # Define target terms for tracking
   targetTerms = ['python', 'pydata','pycones']
   # Init the streamer with terms
   streamer.filter(track=targetTerms)
github SambitAcharya / Mini-Projects / Python / Stream-Tweets / stream.py View on Github external
saveFile.write(saveThis)
			saveFile.write('\n')
			saveFile.close()
			return True

		except BaseException, e:
			print 'failed ondata,', str(e)
			time.sleep(5)

	def on_error(self,status):
		print status

#Sending twitter authentication information
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["2015"]) # Topic goes here
github piratefsh / set-solver / bot.py View on Github external
def listen():
    my_listener = listener_tweeter()
    stream = tweepy.Stream(auth, my_listener)
    stream.userstream(_with='user')
github wataruhashimoto52 / Seq2Seq-chatbot / twitter_listener.py View on Github external
def tweet_listener():
    CONSUMER_KEY = os.environ['CONSUMER_KEY']
    CONSUMER_SECRET = os.environ['CONSUMER_SECRET']
    ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
    ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET']

    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    api = tweepy.API(auth)

    while True:
        try:
            stream = tweepy.Stream(auth=api.auth,
                                   listener=StreamListener(api))
            print("listener starting...")
            stream.userstream()
        except Exception as e:
            print(e)
            print(e.__doc__)
github CruiseDevice / twweet-cli / twweet_cli / Listener.py View on Github external
def auth_streamer(self):
        stream = tweepy.Stream(auth=self.twweeter_obj.api.auth,
                               listener=self.stream_listener_ob)
        return stream
github invinst / CPDB / twitterbot / twitter_bot.py View on Github external
def listen_to_tweets(self, handler):
        stream = tweepy.Stream(auth=self.api.auth, listener=handler)
        is_ok = self.handle_stream(stream)

        bot_log('Ready to receive tweet')
        while not is_ok and settings.DJANGO_ENV != 'test':
            is_ok = self.handle_stream(stream)
github scoliann / SpreadHappiness / findSadPeople.py View on Github external
def getSadPeople(numTweets):

	# Read in authentication credentials from parameters.txt
	consumerKey = readParameters('consumerKey')
	consumerSecret = readParameters('consumerSecret')
	accessToken = readParameters('accessToken')
	accessTokenSecret = readParameters('accessTokenSecret')

	# Connect to the Twitter API
	auth = tweepy.OAuthHandler(consumerKey, consumerSecret)
	auth.set_access_token(accessToken, accessTokenSecret)

	# Create a listener and begin streaming tweets
	sid = SentimentIntensityAnalyzer()
	listener = StdOutListener(numTweets, sid)
	stream = tweepy.Stream(auth, listener)
	stream.filter(track=['bad day i'], languages=['en'])

	# Return values
	return listener.sadPeople
github marcua / tweeql / old / streamwatcher.py View on Github external
def main():
    # Prompt for login credentials and setup stream object
    username = raw_input('Twitter username: ')
    password = getpass('Twitter password: ')
    stream = tweepy.Stream(username, password, StreamWatcherListener(), timeout=None)

    # Prompt for mode of streaming
    valid_modes = ['sample', 'filter']
    while True:
        mode = raw_input('Mode? [sample/filter] ')
        if mode in valid_modes:
            break
        print 'Invalid mode! Try again.'

    if mode == 'sample':
        stream.sample()

    elif mode == 'filter':
        follow_list = raw_input('Users to follow (comma separated): ').strip()
        track_list = raw_input('Keywords to track (comma seperated): ').strip()
        if follow_list:
github GoogleCloudPlatform / kubernetes-bigquery-python / pubsub / pubsub-pipe-image / twitter-to-pubsub.py View on Github external
print 'count is: %s at %s' % (self.count, datetime.datetime.now())
        return True

    def on_error(self, status):
        print status


if __name__ == '__main__':
    print '....'
    listener = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    print 'stream mode is: %s' % os.environ['TWSTREAMMODE']

    stream = Stream(auth, listener)
    # set up the streaming depending upon whether our mode is 'sample', which
    # will sample the twitter public stream. If not 'sample', instead track
    # the given set of keywords.
    # This environment var is set in the 'twitter-stream.yaml' file.
    if os.environ['TWSTREAMMODE'] == 'sample':
        stream.sample()
    else:
        stream.filter(
                track=['bigdata', 'kubernetes', 'bigquery', 'docker', 'google',
                       'googlecloud', 'golang', 'dataflow',
                       'containers', 'appengine', 'gcp', 'compute',
                       'scalability', 'gigaom', 'news', 'tech', 'apple',
                       'amazon', 'cluster', 'distributed', 'computing',
                       'cloud', 'android', 'mobile', 'ios', 'iphone',
                       'python', 'recode', 'techcrunch', 'timoreilly']
                )