Skip to content

Instantly share code, notes, and snippets.

@salty-horse
Created January 17, 2016 21:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salty-horse/b868ab0006e7ee3b3227 to your computer and use it in GitHub Desktop.
Save salty-horse/b868ab0006e7ee3b3227 to your computer and use it in GitHub Desktop.
Fetches followers from Twitter
#!/usr/bin/env python
import json
import time
from datetime import datetime
from secret import TWITTER_API_KEY, TWITTER_API_SECRET, TWITTER_ACCESS_TOKEN, TWITTER_TOKEN_SECRET
import tweepy
USERNAME = 'YOUR_USERNAME_HERE'
def limit_handled(cursor):
while True:
try:
yield cursor.next()
except tweepy.RateLimitError:
print datetime.now(), 'Sleeping'
time.sleep(15 * 60)
auth = tweepy.OAuthHandler(TWITTER_API_KEY, TWITTER_API_SECRET)
auth.secure = True
auth.set_access_token(TWITTER_ACCESS_TOKEN, TWITTER_TOKEN_SECRET)
api = tweepy.API(auth)
cur = limit_handled(tweepy.Cursor(api.followers, id=USERNAME, count=200, skip_status=True).pages())
for i, page in enumerate(cur):
print datetime.now(), 'getting', i
with open('followers_{:05}.txt'.format(i), 'w') as f:
json.dump([u._json for u in page], f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment