Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TaipowerToSlack

TaipowerToSlack is a tool that fetches the "Power Information of Today" from Taipower and sends the data to a designated Slack channel, allowing users to easily monitor Taiwan's power supply status.

Taipower's "Power Information of Today" page:

Please note that this is primarily a shell script demo, with code that might be less elegant and some hard-coded values.

Screenshots

Slack Screenshot:

SlackScreenshot

Terminal Screenshot:

TerminalScreenshot

Setup and Usage

1. Obtain your Slack Incoming Webhook URL

Refer to Slack's Documentation for details on how to obtain an Incoming Webhook URL for your Slack channel.

2. Clone this repository or download the script

Clone the repository:

git clone https://github.com/PeterDaveHello/TaipowerToSlack

Or, download the run.sh script directly, and make the run.sh script executable:

curl https://github.com/PeterDaveHello/TaipowerToSlack/raw/master/run.sh -o /path/to/TaipowerToSlack/run.sh
chmod +x /path/to/TaipowerToSlack/run.sh

3. Configure and execute the script

Navigate to the directory containing the run.sh script.

Set the SLACK_HOOK variable in the shell script, or pass it when running the script:

SLACK_HOOK=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX ./run.sh

The result should be displayed on your Slack channel as shown in the screenshot.

4. Optional: Post to Slack only when the status changes

To enable this option, you can either set the STATELESS and ONLY_POST_ON_STATUS_CHANGE environment variables when running the script or modify them directly in the run.sh script:

  • Pass the variables when running the script:

    STATELESS=false ONLY_POST_ON_STATUS_CHANGE=true ./run.sh
  • Or modify the run.sh script:

    STATELESS="false"
    ONLY_POST_ON_STATUS_CHANGE="true"

With either configuration, the script will use the file ~/.taipower.status to store the status and only post a message to Slack when the status changes.

Dependencies

  • jq: for parsing JSON data
  • curl: for fetching JSON data from the Taipower API
  • bash: for running the shell script
  • mktemp: for creating temporary files
  • bc: for calculating percentages from data

If any of these tools are missing, you can usually install them using your system's package manager (e.g., apt, yum, or pacman).

License

This project is released under the WTFPL v2 license.

About

Fetch Taipower's "Power Information of Today", and send the information to your Slack channel

Topics

Resources

Stars

Watchers

Forks

Used by

Contributors

Languages