[PYTHON] Tweet the triple forecast of the boat race on Twitter

Introduction

I have been keeping the boat race triple forecast for the past month or so, and I am posting the result on Twitter. (→ Is a good prediction right today) I'm getting used to the operation, and I'm happy that the number of followers has increased little by little, and I want to gradually increase the information dissemination! !! So, I tried to create a mechanism for Twitter (semi) automatic posting.

Register on Twitter Development

I referred to this article. ↓ Summary of procedures from Twitter API registration (account application method) to approval * Information as of August 2019

The difference in my case is that it took about 20 days to approve ...

==History== (1) After completing the procedure according to the above link, I received an email from Twitter saying "Please tell me your intention to use", so I replied. (I should have received the same question when applying on the Web ...) image.png ② Leave for almost 3 weeks (tears) ③ After that, get an email saying "I'm sorry, I approved it." ~~ Even if I was approved immediately, I wouldn't have touched it, and ~~ I received it with a relaxed heart.

image.png

So let's tweet! !!

import twitter

auth = twitter.OAuth(consumer_key="API key here",
consumer_secret="API Secret here",
token="Access token here",
token_secret="Access token secret here")

t = twitter.Twitter(auth=auth)

#Randomly select one race from the prediction list.
sample = df_pred.sample(n=1).values
text = sample[0][0]+'No.'+sample[0][1]+'The triplet of'+sample[0][2]+'Pay attention to.'

#Tweet text creation
status=d_tdy+"Introducing one of the expectations!\n-->"+text+"\n"+\
"For other information, visit the following site!\n https://youhaveniceboat.pythonanywhere.com\n"+\
" #python #boatrace #Automatic posting#"+sample[0][0]

#Post
t.statuses.update(status=status) #Post to Twitter

You can get the API key and Access token that you have to enter by pressing "Create an app" from the Twitter developer Apps. image.png

You can check the Key like this. image.png

did it! !!

It was easy! This seems to save a little time. image.png

Recommended Posts

Tweet the triple forecast of the boat race on Twitter
Post the subject of Gmail on twitter
Try to estimate the number of likes on Twitter
I checked the image of Science University on Twitter with Word2Vec.
Try to predict the triplet of boat race by ranking learning
[Memo] Tweet on twitter with python
Tweet the weather forecast with a bot
Get delay information on Twitter and tweet
Investigate the effect of outliers on correlation
Tweet using the Twitter API in Python
Display the graph of tensorBoard on jupyter
Change the order of PostgreSQL on Heroku
The epidemic forecast of the new coronavirus was released on the Web at explosive speed
Tweet regularly with the Go language Twitter API
Tweet the weather forecast with a bot Part 2
The behavior of signal () depends on the compile options
Use the latest version of PyCharm on Ubuntu
Calculate the probability of outliers on a boxplot
At the time of python update on ubuntu
Change the resolution of Ubuntu running on VirtualBox
[AWS S3] Confirmation of the existence of folders on S3
Save the search results on Twitter to CSV.