user_group.add_argument("--screen_name", "-s", help="User's screen name")
user_group.add_argument("--user_id", "-i", help="User's ID")

args = parser.parse_args()

api = tweepy.API(get_oauth_handler())

user_arg = {}
if args.screen_name:
    user_arg["screen_name"] = args.screen_name
elif args.user_id:
    user_arg["user_id"] = args.user_id

display_user = list(user_arg.values())[0]
logger.info("Getting %s's timeline", display_user)

page = 0
total_posts = 0
while True:
    page += 1
    statuses = handle_rate_limit(api, "user_timeline", page=page, **user_arg)

    if not statuses:
        break

    total_posts += len(statuses)
    for status in statuses:
        print(json.dumps(status._json))

logger.info("Found %d tweets on %s's timeline", total_posts, display_user)
Beispiel #2
0
#!/usr/bin/env python3

import argparse
import json

import tweepy

from util import get_oauth_handler, handle_rate_limit

parser = argparse.ArgumentParser(description="Fetch information about a Twitter user")
parser.add_argument("screen_name", help="User's screen name")
args = parser.parse_args()

api = tweepy.API(get_oauth_handler())

user = handle_rate_limit(api, "get_user", screen_name=args.screen_name)

print(json.dumps(user._json))
# The lookup users endpoint only accepts 100 user IDs at a time.
# To run this with a list of more than 100 IDs, use:
#  cat user_ids.txt | xargs -n 100 ./lookup_users.py

import argparse
import json

import tweepy

from util import logger, get_oauth_handler, handle_rate_limit

parser = argparse.ArgumentParser(description="Fetch information about users")
parser.add_argument("user_ids", help="User ID or screen name", metavar="user_id", nargs="+")
parser.add_argument("-s", "--screen-name", action="store_true", dest="using_screen_names",
                    help="Use this if passing screen names instead of user IDs")
args = parser.parse_args()

api = tweepy.API(get_oauth_handler())

logger.info("Looking up %d users", len(args.user_ids))
api_args = {}
if args.using_screen_names:
    api_args["screen_names"] = args.user_ids
else:
    api_args["user_ids"] = args.user_ids
users = handle_rate_limit(api, "lookup_users", **api_args)
for user in users:
    print(json.dumps(user._json))

logger.info("Found %d users", len(users))