Created
January 4, 2018 11:58
-
-
Save miya/6802bce225e453a489b92198c784da57 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 | |
def api(): #関数apiを生成します。https://apps.twitter.com にて consumerkey等を取得して各自で代入して下さい | |
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) | |
api = tweepy.API(auth) | |
return api | |
dic = {} #辞書を定義しておきます。 | |
for tweet in api().search('仮想通貨'): #エゴサ用の単語を入れます。 | |
if tweet.retweeted == False: #リツイート”していない”ツイートだけを抽出。 | |
text = tweet.text #ツイートのテキスト部分を変数textに代入。 | |
id = tweet.id #ツイートの識別番号を変数idに代入 | |
dic.update({id:text}) #変数textと変数idの紐付けをし、辞書dicに追加。 | |
if '@' in dic[id]: #辞書dicにキーである変数idを代入し、テキスト本文を出力。@を含むツイート(リプライ)を除外。 | |
pass | |
else: | |
api().retweet(id) #リツイートする | |
#api().create_favorite(id) どうせリツイートするならふぁぼっちゃえばいいじゃないですか。 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment