Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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
def listen():
my_listener = listener_tweeter()
stream = tweepy.Stream(auth, my_listener)
stream.userstream(_with='user')
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__)
def auth_streamer(self):
stream = tweepy.Stream(auth=self.twweeter_obj.api.auth,
listener=self.stream_listener_ob)
return stream
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)
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
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:
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']
)