This project is an addition to my Nest Project, but works as a standalone as well. Simply remove the functions you don't want. In essence it retrieves several weather data and sends it to your Telegram account. It also stores the data in a JSON file and sends it to another server (in my case where my Nest Project is hosted).
- /start - Initiates the bot and provides a welcome message.
- /menu - Displays the menu with available weather options.
- Weather Summaries: Provides a concise summary of current weather conditions, including temperature, wind speed, and a brief description.
- Detailed Weather Information: Offers detailed weather data, including temperature, humidity, wind direction and speed, UV index, sunrise and sunset times, and forecasts for today and tomorrow.
- Authorized Access: Ensures that only authorized users can access the bot’s functionalities.
- Automatic Logging: Logs weather data twice per hour and more detailed data a few times per day.
- Weather Data Retrieval: Fetches weather data from the KNMI API and handles potential errors and retries.
- UV Data Retrieval: Obtains UV index data from the OpenUV API, with support for both primary and backup API keys.
- Data Processing: Processes raw weather and UV data to create user-friendly summaries and detailed reports.
- Data Transmission: Securely transmits weather data to a designated server using SCP.
- Scheduled Updates: Supports scheduling of regular weather updates using the schedule module.
weather_bot.py: The main script.
weather_functions.py: Functions used in the script.
weather_update.py: The weather update function.
.env.example: An example .env file.
weather_bot.service: A systemd service file.
weather_update.service: A systemd service file.
- Python 3.x
pippackage manager- A Telegram bot token. You can get one by creating a bot through the BotFather.
- API keys for the OpenUV and KNMI APIs
- Encryption key. Check documentation how to get one.
-
Clone the repository:
git clone https://github.com/MadeByAdem/WeerBot cd WeerBot -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Set up your environment variables:
Copy the
.env.examplefile to.envand variables with your keys.cp .env.example .env
-
Run the bot:
python weather_bot.py
-
Modify the service files:
Update the
weather_bot.servicefile with your actual paths:[Unit] Description=Weather Bot After=network.target [Service] ExecStart=/your/path/to/weather_bot/venv/bin/python /your/path/to/weather_bot/weather_bot.py WorkingDirectory=/your/path/to/weather_bot User=root Restart=always [Install] WantedBy=multi-user.target
Update the
weather_update.servicefile with your actual paths:[Unit] Description=Weather Update After=network.target [Service] ExecStart=/your/path/to/weather_bot/venv/bin/python /your/path/to/weather_bot/weather_update.py WorkingDirectory=/your/path/to/weather_bot User=root Restart=always [Install] WantedBy=multi-user.target
-
Copy the service file to systemd:
sudo cp weather_bot.service /etc/systemd/system/ sudo cp weather_update.service /etc/systemd/system/
-
Reload systemd and start the service:
sudo systemctl daemon-reload sudo systemctl start weather_bot.service sudo systemctl start weather_update.service
-
Enable the service to start on boot:
sudo systemctl enable weather_bot.service sudo systemctl enable weather_update.service
- Start a chat with your bot on Telegram.
- Use the
/startcommand to receive the welcome message. - Use the
/menucommand to see the available weather options.
SECRET_TOKEN_WEATHERBOT : Your Telegram bot token.
CHAT_ID_PERSON_1 : Chat ID of the first person.
CHAT_ID_PERSON_2 : Chat ID of the second person. You can add more, just modify the functions.
SSHKEY : If you want to send the json to another server. Make sure this sshkey is added to the receiving server.
RECEIVING_SERVER : The IP address and port of the receiving server.
RECEIVING_FILE_PATH : The path on the receiving server where the data should be stored.
LOG_DIRECTORY : The directory where the log file is stored.
LOG_FILE_NAME : The name of the log file.
KNMI_API_KEY : Your KNMI API key.
KNMI_LOCATION_CODE : The location you want to receive data from (format: latitude,longitude).
WEATHER_JSON_FILE_PATH : The path where the json file is stored.
UV_API_KEY : Your OpenUV API key.
UV_API_BACKUP_KEY : Your OpenUV backup API key (in case of to many api requests)
ENCRYPTION_KEY : Your encryption key \
Feel free to submit issues or pull requests if you have suggestions for improvements or new features. Please follow the existing coding style.
This project is licensed under the Custom License. See the LICENSE file for more details.