"""
Example program for the Stream API. This prints public status messages
-from the "sample" stream as fast as possible.
-
-USAGE
-
- stream-example -t <token> -ts <token_secret> -ck <consumer_key> -cs <consumer_secret>
-
+from the "sample" stream as fast as possible. Use -h for help.
"""
from __future__ import print_function
def parse_arguments():
- parser = argparse.ArgumentParser()
+ parser = argparse.ArgumentParser(description=__doc__ or "")
- parser.add_argument('-t', '--token', help='The Twitter Access Token.')
- parser.add_argument('-ts', '--token-secret', help='The Twitter Access Token Secret.')
- parser.add_argument('-ck', '--consumer-key', help='The Twitter Consumer Key.')
- parser.add_argument('-cs', '--consumer-secret', help='The Twitter Consumer Secret.')
+ parser.add_argument('-t', '--token', required=True, help='The Twitter Access Token.')
+ parser.add_argument('-ts', '--token-secret', required=True, help='The Twitter Access Token Secret.')
+ parser.add_argument('-ck', '--consumer-key', required=True, help='The Twitter Consumer Key.')
+ parser.add_argument('-cs', '--consumer-secret', required=True, help='The Twitter Consumer Secret.')
parser.add_argument('-us', '--user-stream', action='store_true', help='Connect to the user stream endpoint.')
parser.add_argument('-ss', '--site-stream', action='store_true', help='Connect to the site stream endpoint.')
parser.add_argument('-to', '--timeout', help='Timeout for the stream (seconds)')
parser.add_argument('-nb', '--no-block', action='store_true', help='Set stream to non-blocking')
- parser.add_argument('-tt', '--track', help='Search the stream for specific text')
+ parser.add_argument('-tt', '--track-keywords', help='Search the stream for specific text')
return parser.parse_args()
def main():
tweet_iter = stream.site()
else:
stream = TwitterStream(auth=auth, timeout=args.timeout, block=not args.no_block)
- if args.track:
- tweet_iter = stream.statuses.filter(track=args.track)
+ if args.track_keywords:
+ tweet_iter = stream.statuses.filter(track=args.track_keywords)
else:
tweet_iter = stream.statuses.sample()