NavyBTSStatusNotifier is a Python script that fetches the status updates from the Capitania dos Portos da Bahia (Navy) website regarding the Bahia de Todos os Santos (BTS) area and sends notifications to a specified Telegram chat.
- Description
- Features
- Requirements
- Installation
- Usage
- Configuration
- Error Handling
- Contributing
- License
NavyBTSStatusNotifier is a simple utility that periodically fetches the status updates related to the Bahia de Todos os Santos (BTS) area from the Capitania dos Portos da Bahia (Navy) website and sends these updates to a specified Telegram chat using the Telegram API.
- Fetches Bahia de Todos os Santos (BTS) area status updates from the Capitania dos Portos da Bahia (Navy) website
- Notifies a Telegram chat with the status updates
- Configurable logging and error handling
- Python 3.x
requests
library (pip install requests
)parsel
library (pip install parsel
)- Valid Telegram bot token and chat ID
- Clone the repository:
git clone https://github.com/your-username/NavyBTSStatusNotifier.git cd NavyBTSStatusNotifier
- Install the required dependencies:
pip install -r requirements.txt
-
Set up the required environment variables:
TELEGRAM_TOKEN
: Your Telegram bot tokenTELEGRAM_CHAT_ID
: The chat ID to receive notifications
-
Run the script:
python main.py
You can configure the script by modifying the constants in the main.py
file:
BASE_URL
: The URL of the Capitania dos Portos da Bahia (Navy) websiteTIMEOUT
: Timeout for requests (in seconds)LOG_FILE
: Path to the log file
The script handles errors and exceptions gracefully:
TokenNotAvailableException
: Raised if Telegram token is not available in the environmentTimeoutException
: Raised if a timeout occurs during network requests- Other exceptions: General exception handling for unforeseen errors
NavyBTSStatusNotifier can be automatically executed at regular intervals using GitHub Actions. The following GitHub Actions workflow has been set up to run the main.py
script and fetch the BTS status from the Capitania dos Portos da Bahia (Navy) website.
The workflow is triggered by a scheduled event based on a cron expression. It runs the script hourly to ensure timely updates.
- Event: Scheduled event (Cron job)
- Interval: Every hour (at minute 0 past every hour)
-
Checkout Repository Content: The workflow starts by checking out the content of the repository to the GitHub runner.
-
Setup Python Environment: The required Python version (3.9) is set up using the
actions/setup-python
action. -
Install Python Packages: The necessary Python packages are installed using
pip
. -
Execute Python Script (
main.py
): Themain.py
script is executed with the environment variablesTELEGRAM_TOKEN
andTELEGRAM_CHAT_ID
provided as secrets. -
Commit Changes: If there are any changes made during the script execution (such as updating logs), the workflow commits these changes back to the repository.
-
Push Changes: Finally, the changes are pushed to the
main
branch of the repository using thead-m/github-push-action
action.
To enable the automatic script execution and notification, you need to set up the following secrets in your repository:
TELEGRAM_TOKEN
: Your Telegram bot tokenTELEGRAM_CHAT_ID
: The chat ID to receive notifications
These secrets are securely stored and can be accessed within the workflow for authentication purposes.
Please note that you can customize the workflow based on your requirements, such as adjusting the cron schedule or modifying the script execution process.
For more information on GitHub Actions and how to set up and customize workflows, refer to the GitHub Actions documentation.
Contributions are welcome! If you find a bug or have an enhancement in mind, feel free to open an issue or submit a pull request.
- Fork the repository.
- Create a new branch:
git checkout -b my-feature-branch
- Make your changes and commit them:
git commit -m "Add some feature"
- Push to the branch:
git push origin my-feature-branch
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.