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

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
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
Tagged with: