Skip to content

Instantly share code, notes, and snippets.

@amandabee
Last active February 16, 2017 01:56
Show Gist options
  • Save amandabee/726fbd77bc176d2dda8d7404c2f3a487 to your computer and use it in GitHub Desktop.
Save amandabee/726fbd77bc176d2dda8d7404c2f3a487 to your computer and use it in GitHub Desktop.
A quick script for grabbing all of your Twitter follwers.

Run with...

funtimes = FollowerGetter("openlab", cks)

funtimes.get_followers()

TO DO: This works now. :)

consumer_key = "use"
consumer_secret = "your"
access_token = "own"
access_token_secret = "values"
import tweepy
import secrets as cks
import time
import csv
class FollowerGetter:
def __init__(self, username, authfile):
self.username = username
self.authfile = authfile
self.followers = []
def authenticate(self):
cks = self.authfile
auth = tweepy.OAuthHandler(cks.consumer_key, cks.consumer_secret)
auth.set_access_token(cks.access_token, cks.access_token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,
wait_on_rate_limit_notify=True)
return api
def get_followers(self):
self.authenticate()
print ("getting followers")
bunch = self.followers
username = self.username
try:
for page in tweepy.Cursor(api.followers, screen_name=username,
count=200).pages():
bunch.extend(page)
print ("patience!")
except tweepy.error.RateLimitError:
print ("Waiting a minute ...")
time.sleep(60) # Sleep for 60sec
self.write_csv(bunch)
def write_csv(self, resultset):
filename = "followers-" + self.username + ".csv"
with open(filename, 'w', newline='') as fp:
writer = csv.writer(fp, delimiter=',')
writer.writerow(["id", "screen_name", "name", "verified",
"description", "blocked_by"])
for user in resultset:
writer.writerow([user.id, user.screen_name, user.name,
user.verified, user.description,
user.blocked_by])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment