A Python automation script that checks the weather forecast for your location using the OpenWeather API and sends you an email alert if rain is expected.
Perfect for automating daily weather checks and notifying multiple recipients.
- Real-time Weather Data — Uses OpenWeather's 5-day/3-hour forecast API.
- Rain Detection — Alerts if rain is expected in the next 12 hours.
- Email Notifications — Sends alerts to one or more recipients.
- Secure Credentials — Uses
.envfile for API keys and email login (never hardcoded).
- Python 3.8+
- Email account with App Password enabled
- OpenWeather API Key
- Libraries:
pip install -r requirements.txt
1. Clone the repository:
git clone https://github.com/mudasirfayaz/rain-alert-bot.git
cd rain-alert-bot2. Install Dependencies
pip install -r requirements.txt3. Create .env File
Create a .env file in the project root with:
MY_LAT=your_latitude
MY_LONG=your_longitude
SMTP_SERVER="smtp.gmail.com"
MY_EMAIL="your_email@example.com"
APP_PASSWORD="your_email_password_or_app_password"
OWM_API_KEY="your_openweather_api_key"Note
For Gmail, you must enable 2FA and create an App Password.
Google’s Guide on App Passwords
This script works with most email providers that support SMTP.
Simply update the .env file with the correct SMTP_SERVER value.
| Provider | SMTP Server |
|---|---|
| Gmail | smtp.gmail.com |
| Yahoo Mail | smtp.mail.yahoo.com |
| Outlook / Hotmail | smtp.office365.com |
| Zoho Mail | smtp.zoho.com |
| Proton Mail | mail.protonmail.com |
💡 Tip: Always keep your credentials safe by storing them in .env and never committing that file to GitHub.
4. Update recipients.txt
List one email address per line:
friend@example.com
your_second_email@example.com5. Run Locally
python main.pyThis script is designed to run on PythonAnywhere so you don’t need to keep your PC on.
Step 1: Create a PythonAnywhere Account
- Go to https://www.pythonanywhere.com and sign up for a free account.
- Log in to your dashboard.
Step 2: Upload Your Files
- Go to the Files tab.
- Upload:
main.pyrequirements.txtrecipients.txt.env(upload it too, it will remain private)
Step 3: Test the Script
- In the Bash console, run:
python3 main.pyIf it’s raining today, it should send an email.
Step 5: Schedule the Script
- Go to the Tasks tab → Add a New Scheduled Task.
- Set it to run everyday at your preferred time (e.g., 07:00).
- Command to run:
python3 main.py- Click Create.
Your script will now automatically check weather and send email if it's raining today.
📺 Watch one of thes these PythonAnywhere scheduling tutorials:
Schedule Python Tasks on PythonAnywhere
How to Schedule python script on PythonAnywhere
These videos shows how to upload files and set scheduled jobs step-by-step.
Warning
Never commit your .env or recipients.txt files.
- Use
App Passwordsif using Gmail. .gitignoreis already set up to exclude sensitive files.
- Personal rain reminders.
- Group/family weather alerts.
- Office notifications.
- Integration into a home automation system.
mike star*
Telegram: mikestar https://t.me/manchatz
Twitter: mikestar https://x.com/@EleazarTlapala7
This project is licensed under the MIT License — see the LICENSE file for details.