Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
22 lines (19 sloc)
631 Bytes
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
# Chap02-03/twitter_get_user_timeline.py | |
import sys | |
import json | |
from tweepy import Cursor | |
from twitter_client import get_twitter_client | |
def usage(): | |
print("Usage:") | |
print("python {} <username>".format(sys.argv[0])) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
usage() | |
sys.exit(1) | |
user = sys.argv[1] | |
client = get_twitter_client() | |
fname = "user_timeline_{}.jsonl".format(user) | |
with open(fname, 'w') as f: | |
for page in Cursor(client.user_timeline, screen_name=user, count=200).pages(16): | |
for status in page: | |
f.write(json.dumps(status._json)+"\n") |