Created
January 17, 2016 21:59
-
-
Save salty-horse/b868ab0006e7ee3b3227 to your computer and use it in GitHub Desktop.
Fetches followers from Twitter
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
#!/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