LoginSignup
1
1

More than 5 years have passed since last update.

カジュアルに自動retweetがしたかった

Last updated at Posted at 2018-09-01

 過去の投稿を自動でretweetしたい

bitbearsのtwitterのBot化計画のはじめとして、クラウドファンディングのtweetを期間限定でretweetしてくれる機能を適当に作ってみた。
scheduleで等間隔、または、定時の実行を可能にし、
twythonでapiを叩きます。

機能

IDに基づいて、そのtweetがリツイートされているか確認し、されていれば、それを取り消したのち、retweetをします。
tweepyでも、twythonでも、retweetを取り消すコマンドは実装されていなかったので、unretweetのstatusをpostします。

import schedule
import time
from twython import Twython

consumer_key = "*"
consumer_secret = "*"
access_key = "*"
access_secret = "*"

ID = num of your tweet id

twitter = Twython(consumer_key, consumer_secret,
                    access_key, access_secret)

def job():
    if twitter.show_status(id=ID)['retweeted']:
        twitter.post('status/unretweet/%s' % ID)

    twitter.retweet(id = ID)
    print("retweeted")

schedule.every().day.at('08:00').do(job)

schedule.every().day.at('12:00').do(job)

schedule.every().day.at('22:00').do(job)

def main():
    while True:
        schedule.run_pending()
        time.sleep(1)

if __name__ == '__main__':
    main()
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1