-
-
Save andypiper/7d9a742c757d907b47d437030de43b9d to your computer and use it in GitHub Desktop.
random sample of twitter followers for a given screen name
This file contains hidden or 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
# return a random sample of your twitter followers | |
# run like so: | |
# $ python random_followers.py <screen_name> | |
# where <screen_name> is the account you want followers for | |
import sys, random, json, urllib | |
sname = sys.argv[1] | |
ids_raw = urllib.urlopen( | |
"https://api.twitter.com/1/followers/ids.json?screen_name="+sname).read() | |
follower_ids = json.loads(ids_raw)["ids"] | |
sampled = ','.join(random.sample([str(x) for x in follower_ids], 100)) | |
followers_raw = urllib.urlopen( | |
"https://api.twitter.com/1/users/lookup.json?user_id=" + sampled).read() | |
followers = json.loads(followers_raw) | |
for follower in followers: | |
print follower["name"] + "\t" + "http://twitter.com/" + \ | |
follower["screen_name"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment