Last active
June 20, 2016 05:38
-
-
Save kurozumi/b4d219047f8accbfa60aaa166eface47 to your computer and use it in GitHub Desktop.
【Python】tweepyを使ってフォロワーを一括でフォローする方法
This file contains 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
# codin: utf-8 | |
import tweepy | |
def oauth(): | |
consumer_key = "consumer_key" | |
consumer_secret = "consumer_secret" | |
access_key = "access_key" | |
access_secret = "access_secret" | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
return auth | |
# API制限にひっかかったら15分待機するジェネレーター | |
def limit_handled(cursor): | |
while True: | |
try: | |
yield cursor.next() | |
except tweet.RateLimitError: | |
time.sleep(15 * 60) | |
if __name__ == "__main__": | |
api = tweepy.API(oauth()) | |
if follower in limit_handled(tweepy.Cursor(api,followers).items()): | |
if follower.friends_count < 300: | |
follower.follow() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment