Python script that powers the Dealabs office Slack bot who talks about TCL disruptions.
- The bot automatically advise about current disruptions:
- Which lines started or stopped to be disrupted
- When disruption started and stopped
- Can post on multiple Slack channels
- Filter on specific lines
- Ask the bot to check the current status of a specific line using commands (see below for more information) with the same information as above
- Python 3. May eventually works with Python 2 (not tested)
- A Slack team with an already-existing bot
- A Data Grand Lyon (fr) account
- Clone this repo somewhere
pip install -r requirements.txt
python pointtcl.py create_database
Copy the .env.example
file to .env
and fill in the configuration parameters.
Available configuration parameters are:
SLACK_BOT_TOKEN
The bot API token (you can find it when editing the bot settings)SLACK_BOT_ID
You cannot find it now. Fill the otherSLACK_*
configuration paremeters, then run thepython pointtcl.py id
command (see below for more information)SLACK_BOT_NAME
The bot username (not his name or last name!)SEND_DISRUPTION_MESSAGES_TO
A comma-separated list of Slack channel IDs in where to post automatic disruption messages. Empty to disableDISRUPTIONS_LINES
A comma-separated list of allowed TCL line names when sending automatic updates about disruptions. Empty to not filterBOT_ADMINS
A comma-separated list of Slack user IDs who can send admin commands to the bot. Empty to noneGRANDLYON_LOGIN
Username used to login to your data.grandlyon.com accountGRANDLYON_PASSWORD
Password used to login to your data.grandlyon.com account
Our bot is called pointtcl
, but you'll obviously have to replace this name with your own bot name.
@pointtcl [aide|help|comment|dafuq|wut|hein]
@pointtcl [métro|metro] {{line name}}
@pointtcl tram {{line name}}
@pointtcl bus {{line name}}
@pointtcl [funiculaire|funi] {{line name}}
@pointtcl [verif|vérif]
@pointtcl resetbdd
After defining the SLACK_*
configuration parameters in your .env
file, you can run this command to get your bot ID:
python pointtcl.py id
Fill the SLACK_BOT_ID
configuration parameter with the output.
This command will wipe out the database then re-create it from scratch.
python pointtcl.py create_database
python pointtcl.py run
You'll probably need Supervisor or similar to make him always-running.
This command also update the internal database of current disruptions.
python pointtcl.py check_lines
Best usage is to create a Cron job that run it every, say, 5 minutes:
*/5 * * * * cd /path/to/pointtcl && python pointtcl.py check_lines 2>&1
The Slack RTM API is used by the bot to check for incoming message from users. He also uses the Slack Web API to send messages in the appropriate channels. A small SQLite database is used to persist data.
The Data Grand Lyon API (fr) is used to check for disruptions, which is simple JSON data served through HTTP.