A script that automatically posts to Twitter after n seconds. If you start it in the terminal, you have to keep it running. It will end when you 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"Timer test 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()
In this case, execute Post_msg after 5 seconds (about). After posting, it will be printed as Success! Your Tweet and it will end.