[PYTHON] Script to tweet after n seconds

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.

Recommended Posts

Script to tweet after n seconds
Script to tweet with multiples of 3 and numbers with 3 !!
Script to count and stop up to 5 seconds in Python in Blender