Created
June 18, 2018 21:11
-
-
Save bradmontgomery/38cbbb0f85e7db4078e679e98d5012d9 to your computer and use it in GitHub Desktop.
Simple Twython streaming search
This file contains 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
""" | |
See Streaming API: https://twython.readthedocs.io/en/latest/usage/streaming_api.html | |
""" | |
import os | |
import sys | |
from twython import TwythonStreamer | |
class TweetPrinter(TwythonStreamer): | |
def on_success(self, data): | |
if 'text' in data: | |
print("\n--- @{} --------".format(data['user']['screen_name'])) | |
print(data['text']) | |
def on_error(self, status_code, data): | |
print(status_code) | |
if __name__ == "__main__": | |
if len(sys.argv) == 2: | |
stream = MyStreamer( | |
os.environ['TWITTER_CONSUMER_KEY'], | |
os.environ['TWITTER_CONSUMER_SECRET'], | |
os.environ['TWITTER_OAUTH_TOKEN'], | |
os.environ['TWITTER_OAUTH_TOKEN_SECRET'] | |
) | |
stream.statuses.filter(track=sys.argv[1]) | |
else: | |
print("USAGE: python main.py <search>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment