You often want to tweet while you're working, right? However, if you open Twitter there, it's a consistent end. Time goes by by patrolling TL, catching trends, and chasing pushes. But I really want to tweet (only)! So you can tweet directly from the terminal! I noticed that!
So, I would like to actually describe the procedure. (It's easy as long as you can get the Twitter API.) (For those who can read English, it may be faster to see this site. Hmm.)
First, get the API with the account you want to tweet. For API acquisition, I referred to this site.
Once you get the API, it's time to start working. First, go to this page (Developer site). Select App from the account name at the top right of the screen. Now create the app. Please take notes as you can get ** API key ** and ** API secret key ** in the process of creating the app. (It may be good to write down the Bearer token just in case.)
Then edit App Permissions. At first, I think it is ** read only **, so I will change it to ** Read and Write **.
Then get an access token. Select Keys and tokens. (You can switch under the app name.)
** Generate Access Token & Secret **, Make a note of ** Access token ** and ** Access token secret ** as well.
This completes the preparation.
First, create a folder for the project (twitter in this case) in any directory.
$ mkdir twitter
$ cd twitter
$ pipenv install python 3.7.5 #Please build according to your environment
$ pipenv shell
$ touch tweet.py
$ open tweet.py
Install the required libraries.
$ pipenv install tweepy
tweet.py
import tweepy
#Authentication key
#Please change to your own key as appropriate.
consumer_key = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
consumer_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
access_token = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
access_token_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweet = input().split()
api.update_status('\n'.join(tweet))
All you have to do is run it in the terminal!
$ python tweet.py
After executing, enter the words you want to tweet and press enter to complete! You can start a new line by inserting a half-width space.
You can now tweet for the time being! Hooray! Thank you for reading until the end!
Recommended Posts