Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hironow/8488358 to your computer and use it in GitHub Desktop.
Save hironow/8488358 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
import tweepy
import tw_key
CONSUMER_KEY = tw_key.twdict['cons_key']
CONSUMER_SECRET = tw_key.twdict['cons_sec']
ACCESS_TOKEN_KEY = tw_key.twdict['accto_key']
ACCESS_TOKEN_SECRET = tw_key.twdict['accto_sec']
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN_KEY, ACCESS_TOKEN_SECRET)
class Listener(tweepy.StreamListener):
""" Handles tweets received from the stream. """
def on_status(self, status):
""" Prints tweet and hashtags """
print('------------------------------')
print(status.text)
for hashtag in status.entities['hashtags']:
print(hashtag['text']),
print("")
return True
def on_error(self, status_code):
print('Got an error with status code: ' + str(status_code))
return True
def on_timeout(self):
print('Timeout...')
return True
listener = Listener()
stream = tweepy.Stream(auth, listener)
stream.filter(track=['#imas_live'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment