I tweeted from the terminal!

It would be convenient if you could tweet from the terminal!

Preface

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.)

Preparation

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 **. app_permissions.png

Then get an access token. Select Keys and tokens. (You can switch under the app name.) key and token.png

** Generate Access Token & Secret **, Make a note of ** Access token ** and ** Access token secret ** as well.

This completes the preparation.

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.

Postscript

You can now tweet for the time being! Hooray! Thank you for reading until the end!

Recommended Posts

I tweeted from the terminal!
I made a simple timer that can be started from the terminal
I searched for railway senryu from the data
How to measure line speed from the terminal
I counted the grains
I want to see the file name from DataLoader
[Deep Learning from scratch] I implemented the Affine layer
I tried to detect the iris from the camera image
I wanted to use the Python library from MATLAB
How to instantly launch Jupyter Notebook from the terminal
I read the Chainer reference (updated from time to time)
I raised the Python version from 2 to 3, but every time I restart the ubuntu terminal, the version remains 2.
I tried the site "Deploy Azure virtual machine from Go"
I examined the device tree
I tried using the Python library from Ruby with PyCall
Let's search from the procession
Remove the frame from the image
I touched the Qiita API
I want to calculate the allowable downtime from the operating rate
I tried face recognition from the video (OpenCV: python version)
[Python] I installed the game from pip and played it
I tried the changefinder library!
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried to get various information from the codeforces API
I downloaded the python source
I read the SHAP paper
I made something with python that NOW LOADING moves from left to right on the terminal
I want to automatically find high-quality parts from the videos I shot
I tried sending an email from the Sakura server with flask-mail
Terminal association from the server side to Amazon SNS (python + boto3)
I tried to cut out a still image from the video
I checked the usage status of the parking lot from satellite images.
I made a command to display a colorful calendar in the terminal
I tried the TensorFlow tutorial 1st
I got lost in the maze
I tried the Naro novel API 2
I investigated the mechanism of flask-login!
I participated in the ISUCON10 qualifying!
DJango Memo: From the beginning (preparation)
Existence from the viewpoint of Python
I tried the TensorFlow tutorial 2nd
I calculated the stochastic integral (I to integral)
I investigated how the scope looks
I liked the tweet with python. ..
Use the Flickr API from Python
Gender is determined from the name.
Get the value from the [Django] Form
I wrote the queue in Python
I tried task queuing from Celery
Learn from the winning code-Mercari Competition ①-
I tried the Naruro novel API
Let's cut the face from the image
Get the address from the zip code
Change the xfce4 terminal cursor type
I tried to move the ball
I tried using the checkio API
I wrote the stack in Python
I tried to estimate the interval.
I don't know the value error
I investigated the device tree Overlay
I checked the gift tax amount