Exemplo n.º 1
0
 def __call__(self, twitter, options):
     statuses = self.getStatuses(twitter, options)
     sf = get_formatter('status', options)
     for status in statuses:
         statusStr = sf(status, options)
         if statusStr.strip():
             printNicely(statusStr)
Exemplo n.º 2
0
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'])
Exemplo n.º 3
0
 def __call__(self, twitter, options):
     if not (options['extra_args'] and options['extra_args'][0]):
         raise APIHTTPError("You need to specify a user (screen name)")
     af = get_formatter('admin', options)
     try:
         user = self.getUser(twitter, options['extra_args'][0])
     except APIHTTPError as e:
         print("There was a problem following or leaving specified user.")
         print("You may be trying to follow a user your already following;")
         print("Leaving a user you are not currently following;")
         print("Or the user may not exist.")
         print("Sorry.")
         print()
         print(e)
     else:
         printNicely(af(options['action'], user))
Exemplo n.º 4
0
    def getStatuses(self, twitter, options):
        if not options['extra_args']:
            raise APIHTTPError("Please provide a user to query for lists")

        screen_name = options['extra_args'][0]

        if not options['extra_args'][1:]:
            lists = twitter.user.lists(user=screen_name)['lists']
            if not lists:
                printNicely("This user has no lists.")
            for list in lists:
                lf = get_formatter('lists', options)
                printNicely(lf(list))
            return []
        else:
            return reversed(twitter.user.lists.list.statuses(
                    user=screen_name, list=options['extra_args'][1]))
Exemplo n.º 5
0
    def __call__(self, twitter, options):
        # We need to be pointing at search.twitter.com to work, and it is less
        # tangly to do it here than in the main()
        twitter.domain = "search.twitter.com"
        twitter.uriparts = ()

        # We need to bypass the TwitterCall parameter encoding, so we
        # don't encode the plus sign, so we have to encode it ourselves
        query_string = "+".join(
            [quote(term)
             for term in options['extra_args']])

        results = twitter.search(q=query_string)['results']
        f = get_formatter('search', options)
        for result in results:
            resultStr = f(result, options)
            if resultStr.strip():
                printNicely(resultStr)
Exemplo n.º 6
0
def get_tweets(twitter, screen_name, max_id=None):
    kwargs = dict(count=3200, screen_name=screen_name)
    if max_id:
        kwargs['max_id'] = max_id

    n_tweets = 0
    tweets = twitter.statuses.user_timeline(**kwargs)

    for tweet in tweets.response:
        if tweet['id'] == max_id:
            continue
        print("%s %s\nDate: %s" % (tweet['user']['screen_name'],
                                   tweet['id'],
                                   tweet['created_at']))
        if tweet.get('in_reply_to_status_id'):
            print("In-Reply-To: %s" % tweet['in_reply_to_status_id'])
        print()
        for line in tweet['text'].splitlines():
            printNicely('    ' + line + '\n')
        print()
        print()
        max_id = tweet['id']
        n_tweets += 1
    return n_tweets, max_id