Last active
April 27, 2016 19:20
-
-
Save jeremylow/67d892cd03d7e9488d8a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import tweepy | |
import gb_config as gb_config | |
USERNAME = '@twitter' | |
class MentionsListener(tweepy.StreamListener): | |
""" Listens for mentions of USERNAME. """ | |
def _get_api(self): | |
auth = tweepy.OAuthHandler( | |
gb_config.CONSUMER_KEY, | |
gb_config.CONSUMER_SECRET) | |
auth.set_access_token(gb_config.ACCESS_KEY, gb_config.ACCESS_SECRET) | |
api = tweepy.API(auth, wait_on_rate_limit=True) | |
return api | |
def on_connect(self): | |
self.api = self._get_api() | |
print('Connected!') | |
def on_status(self, status): | |
# Do stuff. | |
pass | |
def main(): | |
auth = tweepy.OAuthHandler( | |
gb_config.CONSUMER_KEY, | |
gb_config.CONSUMER_SECRET) | |
auth.set_access_token(gb_config.ACCESS_KEY, gb_config.ACCESS_SECRET) | |
stream = tweepy.Stream(auth, MentionsListener()) | |
stream.filter(track=[USERNAME]) | |
if __name__ == '__main__': | |
try: | |
main() | |
except KeyboardInterrupt: | |
print("\n\nLater, alligator\n\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment