As the title says, I made a LINE bot that will tell you information about Pokemon that appears in the Galar region (Sword Shield), so I would like to summarize it briefly. Below is a screen image.
Please refer to [GitHub] for the file structure.
Install the required libraries from the following Pipfile using pipenv. For some reason psycopg2
cannot be installed normally, so I have included psycopg2-binary
. (The cause of this area is unknown.)
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
flask = "==1.1.2"
line-bot-sdk = "==1.16.0"
sqlalchemy = "==1.3.17"
psycopg2-binary = "==2.8.5"
[requires]
python_version = "3.8"
-(I think most people have one) As a prerequisite, you need a LINE account. If you already have an account, please register to use the API from [LINE Developers].
--Create a new channel after registration.
--After adding a channel, go to [Channel Basic Settings]-> [LINE Official Account Manager]-> [Response Settings Tab], and then go to Response Message OFF
(it can be ON, but it is a little subtle if the default message is inserted one by one). Set to Webhook ON
.
--Check the channel secret
in the channel preferences and the channel access token
in the Messaging API settings. This will be needed later when setting environment variables on Heroku.
(This is needed after working on Heroku)
--Go to Webhook Settings
from Messaging API Settings and enter https: // {app name} .herokuapp.com / callback in Webhook URL
.
-Register at [Heroku]. --Install the required commands with brew. --Login with the following command. --Set environment variables with the following command.
$ brew install heroku
$ brew install postgresql
$ heroku login
$ heroku config:set LINE_CHANNEL_ACCESS_TOKEN="***********" --app {app name}
$ heroku config:set LINE_CHANNEL_SECRET="***********" --app {app name}
--Create an empty DB while logged in to heroku.
--Connect to the DB from the terminal.
--Change DB timezone
――I will download a nice CSV data from Kaggle.
――It's Kaggle, but the data of Pokemon is quite substantial. (As expected, global content)
--Create a table. (The SQL statement below is an example.)
--Copy CSV data to DB. This is because the with csv header
below ignores the CSV header and imports it. Please change it if necessary.
$ heroku addons:create heroku-postgresql:hobby-dev -a {app name}
$ heroku pg:psql -a {app name}
#Start connection, create table
app-name::DATABASE=> alter database {Database name} set timezone = 'Asia/Tokyo';
app-name::DATABASE=> create table pokemon_status(
app-name::DATABASE=> id integer not null,
...
...
app-name::DATABASE=> type2 text,
app-name::DATABASE=> primary key (id));
#Copy local CSV to DB
\copy pokemon_status from '{file name}' with csv header;
I think it is registered like this.
runtime.txt List the Python version.
python-3.8.1
requirements.txt Describes the libraries required on the server side.
Flask==1.1.2
line-bot-sdk==1.16.0
psycopg2==2.8.5
Procfile A file required by Heroku that describes how to run the program.
web: python main.py
The main file will be a bit long, so see [GitHub].
PS5 fun! !!