Created
April 8, 2011 10:30
-
-
Save hiromu/909615 to your computer and use it in GitHub Desktop.
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
fav(user, num, api): | |
user - ふぁぼるユーザーのscreen_name | |
num - ふぁぼる回数 | |
api - tweepy.API | |
このコードでは@hiromu1996を100回ふぁぼれる |
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
import tweepy | |
consumer_key = '**********' | |
consumer_secret = '**********' | |
access_key = '**********' | |
access_secret = '**********' | |
def fav(user, num, api): | |
count = 0 | |
id = 0 | |
while count < int(num): | |
if id == 0: | |
tweets = api.user_timeline(user) | |
else: | |
tweets = api.user_timeline(user, max_id=id) | |
for tweet in tweets: | |
id = tweet.id | |
if tweet.favorited == True: | |
continue | |
fav = api.create_favorite(id) | |
count += 1 | |
if count >= int(num): | |
return | |
if __name__ == '__main__': | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
api = tweepy.API(auth_handler=auth) | |
fav('hiromu1996', 100, api) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment