6
6

More than 5 years have passed since last update.

n秒後にツイートするスクリプト

Posted at

n秒後に自動的にTwitterへポストするスクリプト。
ターミナルで起動するなら起動させっぱなしにしないといけません。
POSTすると終了します。

twittimer.py

#!/user/bin/env python
# -*- coding: utf-8 -*-
from requests_oauthlib import OAuth1Session
import sys, codecs
import threading

C_KEY = "***************************"
C_SECRET = "***************************"
A_KEY = "***************************"
A_SECRET = "***************************"


def Post_msg():
    url = "https://api.twitter.com/1.1/statuses/update.json"
    params = {
        "status": u"タイマーのテスト from Pytimer",
        "lang": "ja"
            }
    tw = OAuth1Session(C_KEY,C_SECRET,A_KEY,A_SECRET)
    req = tw.post(url, params = params)
    if req.status_code == 200:
        print "Success! Your Tweet"
    else:
        print req.status_code
    return Post_msg

t=threading.Timer(5,Post_msg)
t.start()

この場合は5秒後(だいたいです)にPost_msgを実行。
ポスト後はSuccess! Your Tweetとプリントされ、終了します。

6
6
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
6
6