
from __future__ import print_function

import sys

from .stream import TwitterStream
from .auth import UserPassAuth
from .util import printNicely

def main(args=sys.argv[1:]):
    if not args[1:]:
        print(__doc__)
        return 1

    # When using twitter stream you must authorize. UserPass or OAuth.
    stream = TwitterStream(auth=UserPassAuth(args[0], args[1]))

    # Iterate over the sample stream.
    tweet_iter = stream.statuses.sample()
    for tweet in tweet_iter:
        # You must test that your tweet has text. It might be a delete
        # or data message.
        if tweet.get('text'):
            printNicely(tweet['text'])


from __future__ import print_function

import argparse

from twitter.stream import TwitterStream
from twitter.oauth import OAuth
from twitter.util import printNicely


def parse_arguments():

    parser = argparse.ArgumentParser()

    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.')

    return parser.parse_args()

##  parse_arguments()


def main():

    args = parse_arguments()

    # When using twitter stream you must authorize.
    stream = TwitterStream(auth=OAuth(args.token, args.token_secret, args.consumer_key, args.consumer_secret))

    # Iterate over the sample stream.
    tweet_iter = stream.statuses.sample()
    for tweet in tweet_iter:
        # You must test that your tweet has text. It might be a delete
        # or data message.
        if tweet.get('text'):
            printNicely(tweet['text'])

##  main()

if __name__ == '__main__':
    main()

Update to use OAuth, take in command line arguments and modify the imports to function from within the module.
Update to use OAuth, take in command line arguments and modify the imports to function from within the module.

  
  from __future__ import print_function
  
- import sys
+ import argparse
  
- from .stream import TwitterStream
+ from twitter.stream import TwitterStream
- from .auth import UserPassAuth
+ from twitter.oauth import OAuth
- from .util import printNicely
+ from twitter.util import printNicely
  
- def main(args=sys.argv[1:]):
-     if not args[1:]:
-         print(__doc__)
-         return 1
  
+ def parse_arguments():
+ 
+     parser = argparse.ArgumentParser()
+ 
+     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.')
+ 
+     return parser.parse_args()
+ 
+ ##  parse_arguments()
+ 
+ 
+ def main():
+ 
+     args = parse_arguments()
+ 
-     # When using twitter stream you must authorize. UserPass or OAuth.
+     # When using twitter stream you must authorize.
-     stream = TwitterStream(auth=UserPassAuth(args[0], args[1]))
+     stream = TwitterStream(auth=OAuth(args.token, args.token_secret, args.consumer_key, args.consumer_secret))
  
      # Iterate over the sample stream.
      tweet_iter = stream.statuses.sample()
      for tweet in tweet_iter:
          # You must test that your tweet has text. It might be a delete
          # or data message.
          if tweet.get('text'):
              printNicely(tweet['text'])
  
+ ##  main()
+ 
+ if __name__ == '__main__':
+     main()
+ 
Update to use OAuth, take in command line arguments and modify the imports to function from within the module.
## Code Before:

from __future__ import print_function

import sys

from .stream import TwitterStream
from .auth import UserPassAuth
from .util import printNicely

def main(args=sys.argv[1:]):
    if not args[1:]:
        print(__doc__)
        return 1

    # When using twitter stream you must authorize. UserPass or OAuth.
    stream = TwitterStream(auth=UserPassAuth(args[0], args[1]))

    # Iterate over the sample stream.
    tweet_iter = stream.statuses.sample()
    for tweet in tweet_iter:
        # You must test that your tweet has text. It might be a delete
        # or data message.
        if tweet.get('text'):
            printNicely(tweet['text'])

## Instruction:
Update to use OAuth, take in command line arguments and modify the imports to function from within the module.
## Code After:

from __future__ import print_function

import argparse

from twitter.stream import TwitterStream
from twitter.oauth import OAuth
from twitter.util import printNicely


def parse_arguments():

    parser = argparse.ArgumentParser()

    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.')

    return parser.parse_args()

##  parse_arguments()


def main():

    args = parse_arguments()

    # When using twitter stream you must authorize.
    stream = TwitterStream(auth=OAuth(args.token, args.token_secret, args.consumer_key, args.consumer_secret))

    # Iterate over the sample stream.
    tweet_iter = stream.statuses.sample()
    for tweet in tweet_iter:
        # You must test that your tweet has text. It might be a delete
        # or data message.
        if tweet.get('text'):
            printNicely(tweet['text'])

##  main()

if __name__ == '__main__':
    main()
