I made a Twitter BOT with GAE (python) (with a reference)

Finished product

Twitter BOT with GAE(python)

Background to this post

I've had more opportunities to use GAE (python) for work since last month, but I haven't tried to make a proper app using GAE (python) from scratch (there was only a guestbook listed in helloworld and official tutorials). ). So, I decided to make a Twitter BOT (because I didn't understand the batch function).

The content is a BOT that automatically posts the names of other summoners who have participated in the recent matches of registered users on Twitter in a famous overseas game called League of Legends. Twitter's OAuth authentication uses tweepy, and League of Legends match results and summoner names are obtained using the RIOT API and the results are stored in ndb.

Implementation procedure

--Use Tweepy to authenticate Twitter with OAuth, and then store information such as Twitter access token in modelUser. -Register your own summoner name on the / registration form screen, and store the summoner name, account Id, etc. obtained via the RIOT API in modelTask. --Using taskqueue (push), pull the name of the summoner who participated in the latest match from the API using the accountId included in the modelTask, and have only 4 participants automatically posted on Twitter.

However, ** There are few GAE (python) implementation examples that can be used as a reference when implementing the above items, or even if there are, there are many cases where the version etc. is too old to work, so I had a lot of trouble. So, this time, I have posted ** more reference URLs ** in the references ...! For the time being, I intend to cover all the places I stumbled upon, so I hope you will find it helpful.

Also, ** the source code and usage of the actual finished product are posted on Github **, so if you want to check the behavior for the time being, please refer to the README on Github and use it for studying.

References

"** Main sites that I referred to when creating this BOT **" Create a Twitter BOT service with GAE / P + Tweepy + RIOT API! (Part 1)

Create a Twitter BOT service with GAE / P + Tweepy + RIOT API! (Part 2)

I tried to get the account information with riot api

"** How to get access keys for Twitter and RIOT API **" [Summary of procedures from Twitter API registration (account application method) to approval * Information as of August 2019](https://qiita.com/kngsym2018/items/2524d21455aac111cdee#consumer-api-keys%E3%82 % A2% E3% 82% AF% E3% 82% BB% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 82% AF% E3% 83% B3% E6% 83% 85 % E5% A0% B1% E3% 82% 92% E4% BD% BF% E7% 94% A8% E3% 81% 97% E3% 81% 9Fpython% E3% 82% B9% E3% 82% AF% E3 % 83% AA% E3% 83% 97% E3% 83% 88)

I tried to get the account information with riot api

"** The site I saw when I struggled with how to install Tweepy **" Create a Twitter Bot for Google App Engine with Flask and Tweepy

"** Tips on how to deploy a third-party python library on GAE **" How to use a third party library on Google App Engine (Python)

Causes and solutions for "ImportError: No module named _winreg" on GAE / Py

[Stack overflow shows that if you don't put setup.cfg, you will get an error even if you pip install in the lib folder](https://stackoverflow.com/questions/24257803/distutilsoptionerror-must-supply-either- home-or-prefix-exec-prefix-not-both)

[List of third-party libraries built into GAE (libraries that can be included in app.yaml)](https://cloud.google.com/appengine/docs/standard/python/tools/built-in-libraries- 27)

[Please refer to here for those who want to pip install by writing in requirement.txt](https://datumstudio.jp/blog/gae%E3%81%A7%E3%82%B5%E3%82 % AF% E3% 83% 83% E3% 81% A8api% E3% 82% B5% E3% 83% BC% E3% 83% 90% E6% A7% 8B% E7% AF% 89)

"** Sites that helped me when I struggled to implement **" Requests-related behavior errors can be resolved by including requests_toolbelt.adapters.appengine

URL referred to when practicing Tweepy's OAuth1a authentication

Be careful when verifying because the same tweet cannot be automatically tweeted continuously and an error is thrown during batch processing

"** Those who want to know about Twitter OAuth authentication **" The most easy-to-understand explanation of OAuth Authentication technology you should know in application development --OAuth 1.0 + OAuth 2.0 + OpenID Connect-

Summary

This time, I created a Twitter BOT using GAE (python). Since there weren't many implementation examples, I was struggling with the official reference for the task queue and detailed specifications around ndb, but I managed to implement it.

If you have a chance to use GAE (python) for work or hobby, please refer to this and proceed with the implementation to deepen your understanding. Please use it for training (please add a star when cloning from Github!)

Impressions when the initial implementation was completed

--Routing should have been combined into one file in routes.py --Maybe I could have used memcache ――I wanted to clean the front screen --Understanding around ndb was less than I expected

Recommended Posts

I made a Twitter BOT with GAE (python) (with a reference)
I made a Twitter fujoshi blocker with Python ①
I made a Mattermost bot with Python (+ Flask)
I made a fortune with Python.
I made a LINE BOT with Python and Heroku
I made a daemon with Python
I made a character counter with Python
I made a Hex map with Python
Let's make a Twitter Bot with Python!
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a neuron simulator with Python
I made a Twitter Bot with Go x Qiita API x Lambda
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
Make a Twitter trend bot with heroku + Python
I made a GUI application with Python + PyQt5
[Python] I made a Youtube Downloader with Tkinter.
I made a LINE Bot with Serverless Framework!
Steps to create a Twitter bot with python
I made a bin picking game with Python
I made blackjack with python!
I made a python text
I made a discord bot
I made blackjack with Python.
I made wordcloud with Python.
[AWS] I made a reminder BOT with LINE WORKS
I made a household account book bot with LINE Bot
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python3 environment on Ubuntu with direnv.
I made a Line-bot using Python!
I made a wikipedia gacha bot
I made a LINE BOT that returns parrots with Go
I made a package to filter time series with python
I made a simple book application with python + Flask ~ Introduction ~
Create a Twitter BOT with the GoogleAppEngine SDK for Python
I made a puzzle game (like) with Tkinter in Python
[AWS] I made a reminder BOT with LINE WORKS (implementation)
[Python] I made a Line bot that randomly asks English words.
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a library to easily read config files with Python
I made a package that can compare morphological analyzers with Python
I made a payroll program in Python!
I drew a heatmap with seaborn [Python]
I made a Nyanko tweet form with Python, Flask and Heroku
I made a lot of files for RDP connection with Python
I made a Twitter bot that mutters Pokemon caught by #PokemonGO
I made a program to collect images in tweets that I liked on twitter with Python
[Python] I made an image viewer with a simple sorting function.
I tried a functional language with Python
I made a shuffle that can be reset (reverted) with Python
What I did with a Python array
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
I made a life game with Numpy
I made a stamp generator with GAN
I made a poker game server chat-holdem using websocket with python
After studying Python3, I made a Slackbot
I made a segment tree with python, so I will introduce it
I wrote a script to create a Twitter Bot development environment quickly with AWS Lambda + Python 2.7