Created
December 25, 2019 03:23
-
-
Save ayutaz/496b5bc9ccccfc88195e4c52c718f221 to your computer and use it in GitHub Desktop.
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 | |
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