Created
November 18, 2011 20:16
-
-
Save turicas/1377625 to your computer and use it in GitHub Desktop.
Get the number of followers and following on Twitter
This file contains 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
alvaro@ideas:~$ ipython --no-banner -i followers_following.py | |
In [1]: number_of_following('turicas') | |
Out[1]: 627 | |
In [2]: number_of_followers('turicas') | |
Out[2]: 1253 |
This file contains 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
import urllib | |
import json | |
URL_API = 'https://api.twitter.com/1/' | |
def number_of_following(username): | |
url = URL_API + 'friends/ids.json?cursor=-1&screen_name=' + username | |
following = urllib.urlopen(url) | |
contents = following.read() | |
list_of_following = json.loads(contents)['ids'] | |
return len(list_of_following) | |
def number_of_followers(username): | |
url = URL_API + 'followers/ids.json?cursor=-1&screen_name=' + username | |
following = urllib.urlopen(url) | |
contents = following.read() | |
list_of_following = json.loads(contents)['ids'] | |
return len(list_of_following) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment