Line Bot that provides information about dengue fever.
Including the following functionality
- Basic Dengue Fever Knowledge
- Real Time Epidemic Information
- Nearby Hospital
- line id: @mosquitoman
- QR Code QR code
git clone --recursive https://github.com/NCKU-CCS/line_bot_server
- Python 3
- pipenv
- pygraphviz (For visualizing Finite State Machine)
- postgres (Database)
# mac
brew install postgresql
# ubuntu
sudo apt-get install postgresql postgresql-contrib
- postgis (Database)
- redis (In Memeory Database)
# mac
brew install redis
# ubuntu
sudo apt-get install redis-server
pipenv install
Currently this repo tracks only denguefever_tw/denguefever_tw/settings/productions.py
All other setting files should be defined under denguefever_tw/denguefever_tw/settings/
Use the following command to setup or change Django settings
export DJANGO_SETTINGS_MODULE="denguefever_tw.settings.your_setting_file"
Change your_setting_file
to corresponding file
e.g. export DJANGO_SETTINGS_MODULE="denguefever_tw.settings.production"
All the sensitive data are not versioned and should be configured by the environment variables.
The variables needed including
DJANGO_SECRET_KEY
(loaded asSECRET_KEY
)LINE_CHANNEL_SECRET
LINE_CHANNEL_ACCESS_TOKEN
POSTGRESQL_NAME
POSTGRESQL_USER
POSTGRESQL_PASSWORD
POSTGRESQL_HOST
POSTGRESQL_PORT
IMGUR_CLIENT_ID
CHROME_DRIVER_PATH
When developing, you should define your own local.py
under settings/
.
This file will be and should be ignored by git.
You should import base.py
first.
from .base import *
Then, set up the following variables
SECRET_KEY
DATABASES
LINE_CHANNEL_SECRET
LINE_CHANNEL_ACCESS_TOKEN
IMGUR_CLIENT_ID
CHROME_DRIVER_PATH
e.g.
from .base import *
SECRET_KEY = 'This is the secret key'
LINE_CHANNEL_SECRET = 'This is your Line channel secret'
LINE_CHANNEL_ACCESS_TOKEN = 'This is your Line access token'
IMGUR_CLIENT_ID = 'This is your client id of Imgur application'
CHROME_DRIVER_PATH = 'This is path of your Chrome browser driver'
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pwd',
'HOST': 'localhost',
'PORT': '',
},
'tainan': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pwd',
'HOST': 'localhost',
'PORT': '',
},
}
Currently postgis
is used with one default
db and one tainan
db.
default
: Store all data other than Tainan hospital datatainan
: Store Tainan hospital data
# mac
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
Import tainan hosptial data
python manage.py import_dengue_hospital
python manage.py import_tainan_minarea
Cache is used to store user state.
Currently redis
server is used
redis-server
- loggers
django
: global loggingdengue_linebot.denguebot_fsm
: FSM logging including all the conditional judgements and operation processes
e.g.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s:%(asctime)s:%(module)s:%(process)d:%(thread)d\n%(message)s'
},
'simple': {
'format': '%(levelname)s\n%(message)s'
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO',
},
'dengue_linebot.denguebot_fsm': {
'handlers': ['console'],
'level': 'INFO',
}
},
}
More detail on Logging System in django
sudo uwsgi --ini server-setting/linebot.ini --touch-reload=`pwd`/server-setting/linebot.ini
sudo killall -s INT uwsgi
touch server-setting/linebot.ini
sudo killall -s INT uwsgi
sudo uwsgi --ini server-setting/linebot.ini --touch-reload=`pwd`/server-setting/linebot.ini
sudo tail -f /var/log/bot_denguefever_daemon.log
Under denguefever_tw/denguefever_tw/static/dengue_bot_config
FSM.json
: Finite state machinedengue_msg.json
: Static Messages
Add https://Your Domain Name
/callback/ to Webhook URL
on your LINE Developer page.
Copyright (c) NCKU The Mosquito Man Project. All rights reserved.
Licensed under the MIT License.