Created
January 5, 2012 09:52
-
-
Save sonkm3/1564483 to your computer and use it in GitHub Desktop.
python twitterのフォロワー一覧をcsvでみたかった
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
# -*- coding: utf-8 -*- | |
import sys, csv, StringIO | |
import tweepy | |
def get_followers(api, screen_name): | |
followers_count = api.get_user(screen_name = screen_name).followers_count | |
cursor = tweepy.Cursor(api.followers, screen_name = screen_name) | |
followers = cursor.items() | |
followers_list = [] | |
count = 1 | |
for follower in followers: | |
_row = ( | |
follower.screen_name, | |
unicode(follower.name), | |
unicode(follower.location), | |
str(follower.created_at), | |
str(follower.followers_count), | |
str(follower.friends_count), | |
str(follower.statuses_count), | |
str(follower.favourites_count), | |
str(follower.lang), | |
str(follower.verified), | |
unicode(follower.description), | |
) | |
row = [ _str.encode('utf8') for _str in _row ] | |
followers_list.append(row) | |
sys.stderr.write(str(count) + '/' + str(followers_count)+"\n") | |
count += 1 | |
return followers_list | |
def main(): | |
stringio = StringIO.StringIO() | |
writer = csv.writer(stringio) | |
csv_header = ( | |
'screen_name', | |
'name', | |
'location', | |
'created_at', | |
'followers_count', | |
'friends_count', | |
'statuses_count', | |
'favourites_count', | |
'lang', | |
'verified', | |
'description', | |
) | |
writer.writerow(csv_header) | |
screen_name = sys.argv[1] | |
api = tweepy.API() | |
writer.writerows(get_followers(api, screen_name)) | |
sys.stdout.write(stringio.getvalue()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment