Skip to content

Instantly share code, notes, and snippets.

@hiromu
Created April 8, 2011 10:30
Show Gist options
  • Save hiromu/909615 to your computer and use it in GitHub Desktop.
Save hiromu/909615 to your computer and use it in GitHub Desktop.
tweepyでふぁぼる
fav(user, num, api):
user - ふぁぼるユーザーのscreen_name
num - ふぁぼる回数
api - tweepy.API
このコードでは@hiromu1996を100回ふぁぼれる
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