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.
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 ...) ② 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.
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.
You can check the Key like this.
It was easy! This seems to save a little time.
Recommended Posts