formatting fix for code
[twitter-api-cdsw-solutions] / solution-followers-3.py
1 # Make a "famous ratio" for a given user which I'll define as 'number
2 # of followers a person has divided by number of people they
3 # follow. Try out @makoshark, and @pontifex (the Pope). Who is higher?
4
5 import encoding_fix
6 import tweepy
7 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
8
9 auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
10 auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
11
12 api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
13
14 def famous_ratio(username):
15     user = api.get_user(username)
16     return(user.followers_count / user.friends_count)
17
18 print("mako: %s" % famous_ratio('makoshark'))
19 print("the pope: %s" % famous_ratio('pontifex'))
20

Benjamin Mako Hill || Want to submit a patch?