Recently I have been obsessed with command line with Python and came across lots of cool things that you can do with Python. You can even Tweet from command line using Python. In order to send tweet from command line we need to use Twython which is Python wrapper for Twitter API. With just eight lines of code we don’t need to visit twitter.com to post a tweet.
Tweet From Command Line Using Python
Firstly you need to create a new app on twitter.
Once you do that you will be redirected to application management here you can find the Consumer Key (API Key) and Consumer Secret (API Secret).
These keys are secret and are not to be shared publicly. Now that you have your keys simply use the keys in the Code below.
from twython import Twython APP_KEY = 'key' # Customer Key here APP_SECRET = 'secret key' # Customer secret here OAUTH_TOKEN = 'access token' # Access Token here OAUTH_TOKEN_SECRET = 'token secret' # Access Token Secret here twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET) var_status=raw_input('enter your tweet'); #accepts input you can type your tweet twitter.update_status(status=var_status); #you can check twitter to see your tweet live
Note: You need to create your access token without it you may not be able to get Token and token secret
Also check Top 10 Twitter Search Tricks.
Give any name to your file suppose tweet.py is the file name. Run this file in the command line and you can send the tweet from command line. I guess it was simple tutorial. There are lots of amazing things you can do with Python. Keep visiting we will share more such tutorials in the coming few days.