[PYTHON] A memo that I stumbled upon when doing a quote RT on Twitter Bot


This is the first Qiita post in my life. Read this article with a Buddha-like heart. I would be grateful if you could point out any mistakes.

what happened?

At school, I took a rest only in the afternoon because of the troublesomeness of the class, so I decided to write a program, so I went to the industrial mechanics and English class.

So I decided to make a "Twitter Bot that uses the automatic tweet of #contributter_report to scatter myself if I was not committed that day" that I wanted to make from before, and I want to make a quote RT in it, so I will investigate However, even if I googled the official document, it does not come out easily. I finally found it there, so I decided to write a Qiita article so that if there is a person like me, I can easily find it in the search results.

How to do quote RT

This is a well-known fact and it would be very embarrassing if only I didn't know it. Quote RT can be done by ** tweeting the URL of the source tweet at the same time as the characters that match the quote RT **.

As an example, if the tweet below is quoted RT, copy the URL of this tweet image.png Just paste the URL of the quoted tweet along with the text to be quoted RT and tweet image.png You can quote RT like this. image.png

Sample code

API key and access token are set in key.py of another file and imported first.

import tweepy

auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
api = tweepy.API(auth)

tmp = 'https://twitter.com/genshi0916/status/'
for tweet in tweepy.Cursor(api.search, q='genshi0916 contribution 0').items(1):
  text = tweet.text
  id = tweet.id

    print("Number of contributions:What does 0 mean?????????????Please make progress\n" + tmp + str(id))
    api.update_status("Number of contributions:What does 0 mean?????????????Please make progress\n" + tmp + str(id))


Get the id of the tweet with tweet.id, and put the part other than the tweet ID in tmp (This time it is'https://twitter.com/genshi0916/status/' because it is a bot that responds only to tweets of genshi0916)

If you keep the user name in this source,

user_name = tweet.user.screen_name

I think it is good to add such as and move tmp to the next line as shown below.

tmp = 'https://twitter.com/'+user_name+'/status/'


Quote RT ** Tweet the characters and the URL of the source tweet **! !! !! !! !! !!

I hope this article has helped someone. Have a good Twitter life with Twitter Bot! !! !!

The source is published on Github, so I will post the url. https://github.com/Genshi0916/genshi-contribution-check


Recommended Posts

A memo that I stumbled upon when doing a quote RT on Twitter Bot
What I stumbled upon when using CodeIgniter on a Linux server
What I did when I stumbled on a Django tutorial
A story that stumbled when I made a chatbot with Transformer
Easy! Implement a Twitter bot that runs on Heroku in Python
I made a Twitter bot that mutters Pokemon caught by #PokemonGO
A story that stumbled upon installing matplotlib
A story that stumbled upon a comparison operation
[Python] I made a bot that tells me the current temperature when I enter a place name on LINE
I made a Discord bot in Python that translates when it reacts
I stumbled upon installing sentencepiece on ubuntu
Create a bot that boosts Twitter trends
I made a LINE Bot that sends recommended images every day on time
I tried to make a translation BOT that works on Discord using googletrans
[Linux] Let's talk about when I stumbled upon a symbolic link I was using.
A memo that I wrote a quicksort in Python
A template that I often use when making Discord BOT in Python (memorial note)
I made a Twitter BOT with GAE (python) (with a reference)
I got a UnicodeDecodeError when pip install on ubuntu
I stumbled upon using MoviePy, so make a note
A memo that I touched the Datastore with python
A memo when Django was released on VPS (preparation)
I stumbled upon PyUnicodeUCS4_FromStringAndSize when inserting TensorFlow with pip
When I tried to build a Rails environment on WSL2 (Ubuntu 20.04LTS), I stumbled and fell.
I made a program to collect images in tweets that I liked on twitter with Python
Memo (March 2020) that I was addicted to when installing Arch Linux on MacBook Air 11'Early 2015
I made a LINE BOT that returns parrots with Go
A story that stumbled when using pip in a proxy environment
I stumbled when I tried to install Basemap, so a memorandum
An error that stumbled upon learning YOLO on Google Colab
When I made a Discord Bot, my classmates destroyed my computer
A note when I can't open Jupyter Notebook on Windows
I made a neural network generator that runs on FPGA