made a collection of twitter api solutions
[twitter-api-cdsw-solutions] / solution-followers-2.py
1 # For each of your followers, find out how many followers they have.
2
3 import encoding_fix
4 import tweepy
5 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
6 import time
7
8 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
9 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
10
11 api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
12
13 user = api.get_user("makoshark")
14
15 for follower in user.followers():
16     print("%s : %s" % (follower.screen_name, follower.followers_count))
17     
18     # According to this page, we can make 180 requests for user
19     # information each 15 minute period or one every 5 seconds:
20     #
21     # https://dev.twitter.com/rest/reference/get/users/show
22     time.sleep(5)
23           

Benjamin Mako Hill || Want to submit a patch?