Last active
December 29, 2015 15:06
-
-
Save maswadkar/3f4857029a820abaa600 to your computer and use it in GitHub Desktop.
Get the list of twitter followers
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
import twitter | |
import pandas as pd | |
import time | |
def give_followers_list(screen_name): | |
total_followers = [] | |
my_cursor = -1 | |
while my_cursor != 0: | |
my_followers = t.followers.list(screen_name=screen_name,count=200,cursor=my_cursor) | |
time.sleep(60) | |
my_cursor = my_followers['next_cursor'] | |
for each_user in my_followers['users']: | |
total_followers.append(each_user['screen_name']) | |
return total_followers | |
CONSUMER_KEY = 'YOUR_CONSUMER_KEY' | |
CONSUMER_SECRET ='YOUR_CONSUMER_SECRET' | |
OAUTH_TOKEN = 'YOUR_OAUTH_TOKEN' | |
OAUTH_TOKEN_SECRET = 'YOUR_OAUTH_TOKEN_SECRET' | |
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,CONSUMER_KEY, CONSUMER_SECRET) | |
t=twitter.Twitter(auth=auth) | |
df = pd.read_excel('sample.xlsx') | |
print(df) | |
master_followers = [] | |
for screen_name in df['screen_names']: | |
try: | |
my_followers = give_followers_list(screen_name) | |
except Exception as e: | |
print(screen_name) | |
print(e) | |
continue | |
for each_follower in my_followers: | |
master_followers.append(each_follower) | |
df = pd.DataFrame(master_followers) | |
df.to_csv('all_followers.csv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment