X-Git-Url: https://projects.mako.cc/source/twitter-api-cdsw-solutions/blobdiff_plain/1e2d406ccc7bfaa9c73ab809367ce5ae2ab6fc79..d4653b5f599083dc7631ff1a215096ac58b626d8:/solution-followers-3.py diff --git a/solution-followers-3.py b/solution-followers-3.py new file mode 100644 index 0000000..8c0ad55 --- /dev/null +++ b/solution-followers-3.py @@ -0,0 +1,20 @@ +# Make a "famous ratio" for a given user which I'll define as 'number +# of followers a person has divided by number of people they +# follow. Try out @makoshark, and @pontifex (the Pope). Who is higher? + +import encoding_fix +import tweepy +from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET + +auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) +auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) + +api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) + +def famous_ratio(username): + user = api.get_user(username) + return(user.followers_count / user.friends_count) + +print("mako: %s" % famous_ratio('makoshark')) +print("the pope: %s" % famous_ratio('pontifex')) +