4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

3の倍数と3の付く数だけ!!を付けてツイートするスクリプト

Last updated at Posted at 2014-03-03

python twitter toolsを利用します。

pip install twitter

次に https://apps.twitter.com/ でtwitterアプリの登録をします。
このとき、Access levelはRead and writeにしておきます。
必要な登録をしてAPI key, API secret, Access token, Access token secretを取得してください。

以下のスクリプトを実行します。

from twitter import *

api_key = "自分の api key"
api_secret = "自分の api secret"
access_token = "自分の access token"
access_token_secret = "自分の access token secret"


twitter = Twitter(auth=OAuth(access_token, access_token_secret, api_key, api_secret))

text = '3の倍数と3の付く数だけ!!を付けてツイートするスクリプトを実行します'
twitter.statuses.update(status=text)

tweet = []
for i in range(1,31):
    if i % 3 == 0:
        tweet.append(str(i) + '!!')

    elif '3' in str(i):
        tweet.append(str(i) + '!!')

    else:
        tweet.append(str(i))

tweet = " ".join(tweet)

twitter.statuses.update(status=tweet)

結果 ![tweet.PNG](https://qiita-image-store.s3.amazonaws.com/0/37662/30031e7a-fbd2-5904-e968-7867ba8a6ffa.png)
【参考】 [Python Twitter Tools 利用ノート](http://www.geocities.jp/showa_yojyo/note/python-twitter-tools.html) [hirooka.pro Python Twitter Tools](https://hirooka.pro/?p=2252)
4
5
4

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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?