Skip to content

Instantly share code, notes, and snippets.

@ayutaz
Created December 25, 2019 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ayutaz/496b5bc9ccccfc88195e4c52c718f221 to your computer and use it in GitHub Desktop.
Save ayutaz/496b5bc9ccccfc88195e4c52c718f221 to your computer and use it in GitHub Desktop.
import tweepy
import config
# OAuth認証
auth = tweepy.OAuthHandler(config.consumer_key,
config.consumer_secret)
auth.set_access_token(config.access_token,
config.access_token_secret)
#利用制限にひっかかた時に必要時間待機する
api = tweepy.API(auth, wait_on_rate_limit=True)
word = 'my word'
count = 300
now_count = 0
# wordが含まれているツイートをrt,followする
for status in api.search(q=word, count=count):
now_count =  1  + now_count
print("現在:" + str(now_count) + "/" + str(count) )
    # ツイートid
    tweet_id = status.id
    # ユーザid
    user_id = status.user.id
    try:
        # リツイート実行
        api.retweet(tweet_id)
        print("リツイートしました")
        # フォロー実行
        api.create_friendship(user_id)
        print("フォローしました")
        print("user_id:" + status.user.screen_name)
        print("tweet text:" + status.text)
        print('-' * 120)
    except:
        print("えらー RTかフォローが重複しています")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment