Skip to content

Instantly share code, notes, and snippets.

@PiotrKrosniak
Last active April 9, 2018 00:25
Show Gist options
  • Select an option

  • Save PiotrKrosniak/84e8a9b1deec9d94a14588f15a9d8314 to your computer and use it in GitHub Desktop.

Select an option

Save PiotrKrosniak/84e8a9b1deec9d94a14588f15a9d8314 to your computer and use it in GitHub Desktop.
import tweepy
import pandas as pd
from datetime import datetime
def lookup_user_list(user_id_list, api):
full_users = []
users_count = len(user_id_list)
try:
for i in range((users_count // 100) + 1):
print i
full_users.extend(api.lookup_users(user_ids=user_id_list[i * 100:min((i + 1) * 100, users_count)]))
return full_users
except tweepy.TweepError:
print('Something went wrong, quitting...')
consumer_key = '' # keep the quotes, replace this with your consumer key
consumer_secret = '' # keep the quotes, replace this with your consumer secret key
access_token = '' # keep the quotes, replace this with your access token
access_token_secret = '' # keep the quotes, replace this with your 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)
ids = []
for page in tweepy.Cursor(api.followers_ids, screen_name="PiotrKrosniak").pages():
ids.extend(page)
results = lookup_user_list(ids, api)
all_users = [{'id': user.id,
'Name': user.name,
'Statuses Count': user.statuses_count,
'Friends Count': user.friends_count,
'Screen Name': user.screen_name,
'Followers Count': user.followers_count,
'Location': user.location,
'Language': user.lang,
'Created at': user.created_at,
'Time zone': user.time_zone,
'Geo enable': user.geo_enabled,
'Description': user.description}
for user in results]
df = pd.DataFrame(all_users)
date = ( datetime.now().strftime('%Y-%m-%d-'))
df.to_csv(date+'followers.csv', index=False, encoding='utf-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment