Tiny snippet of Python code to extract the friends and followers of a given user
On September 21, 2011,
in Code,
by cornelius
Ahead of publishing my TwitterFunctions library of R code (which is constant work in progress) I thought I’d put up some really short Python code for getting a person’s friends and followers. Both scripts rely on Tweepy, my favorite Python implementation of the Twitter API. Install Python (works on Windows as well, not just on Mac/Linux) and then Tweepy on top of that and you are good to go with these two scripts, which can be executed from the command line with
python get_friends.py username
?Download get_friends.py
1 2 3 4 5 6 | import sys import tweepy user = sys.argv[1] for friend in tweepy.api.friends(user): print friend.screen_name |
?Download get_followers.py
1 2 3 4 5 6 | import sys import tweepy user = sys.argv[1] for follower in tweepy.api.followers(user): print follower.screen_name |
