A real-time weather monitoring and alerting system built in Go that tracks weather conditions and sends notifications when specified thresholds are exceeded.
- Real-time Weather Monitoring: Fetches current weather data using WeatherAPI
- Customizable Alert System: Set thresholds for temperature, humidity, wind speed, and more
- Multiple Notification Channels:
- Console output with colored formatting
- Email notifications (Gmail SMTP)
- File logging with detailed reports
- Scheduled Monitoring: Configurable monitoring intervals
- Alert Conditions:
- High/Low temperature alerts
- High humidity alerts
- High wind speed alerts
- Extreme weather condition alerts
WeatherWatch/
βββ cmd/
β βββ weather-alert/
β βββ main.go # Application entry point
βββ alert/
β βββ alert.go # Alert condition logic
βββ api/
β βββ weatherapi.go # WeatherAPI integration
βββ notify/
β βββ console.go # Console notification system
β βββ file.go # File logging system
β βββ sendEmail.go # Email notification system
βββ scheduler/
β βββ scheduler.go # Weather monitoring scheduler
βββ utils/
β βββ format.go # Message formatting utilities
βββ .env # Environment configuration
βββ weatherReport.txt # Generated weather logs
βββ go.mod # Go module file
βββ go.sum # Go dependencies
βββ Makefile # Build automation
βββ README.md # This file
- Go 1.19 or higher
- WeatherAPI account (free tier available)
- Gmail account with App Password (for email notifications)
git clone https://github.com/yourusername/WeatherWatch.git
cd WeatherWatch
go mod tidy
Create a .env
file in the root directory:
# WeatherAPI Configuration
API_KEY=your_weatherapi_key_here
# Email Configuration (Gmail SMTP)
SENDER_EMAIL="your-email@gmail.com"
SENDER_PASSWORD="your-app-password"
FROM_EMAIL_SMTP="smtp.gmail.com"
SMTP_ADDR="smtp.gmail.com:587"
RECIPIENT_EMAIL="recipient@gmail.com"
- Visit WeatherAPI.com
- Sign up for a free account
- Copy your API key to the
.env
file
- Enable 2-Factor Authentication on your Gmail account
- Go to Google Account Settings β Security β App Passwords
- Generate a new app password
- Use this password in your
.env
file (not your regular Gmail password)
Run the weather monitoring system:
make run
Or directly with Go:
go run ./cmd/weather-alert/main.go
Edit cmd/weather-alert/main.go
:
scheduler.CheckWeatherOnSchedule(1, "Lagos") // Change "Lagos" to your city
scheduler.CheckWeatherOnSchedule(5, "Lagos") // Check every 5 minutes
Edit alert/alert.go
to modify temperature, humidity, and wind speed thresholds:
// Example thresholds
const (
HIGH_TEMP_THRESHOLD = 35.0 // Celsius
LOW_TEMP_THRESHOLD = 5.0 // Celsius
HIGH_HUMIDITY_THRESHOLD = 85 // Percentage
HIGH_WIND_THRESHOLD = 25.0 // km/h
)
The system monitors and alerts on:
- High Temperature: Above configured threshold
- Low Temperature: Below configured threshold
- High Humidity: Above configured percentage
- High Wind Speed: Above configured speed
- Extreme Weather: Severe weather conditions
π Lagos, Nigeria
π Local Time: 2025-07-13 09:10
π‘οΈ Temperature: 25.0Β°C (Feels like: 27.0Β°C)
βοΈ Condition: Partly cloudy
π§ Humidity: 89%
π¬οΈ Wind: 20.2 kph (SW)
βοΈ Cloud Cover: 50%
β οΈ ALERTS Triggered
π Lagos, Nigeria | π 2025-07-13 00:00
---------------------------------
π¬οΈ High Wind Speed: 26.6 kph (threshold: 22.3 kph)
cmd/weather-alert/main.go
: Application entry pointscheduler/scheduler.go
: Main monitoring loop with signal handlingapi/weatherapi.go
: WeatherAPI client and data structuresalert/alert.go
: Alert condition checking logicnotify/
: Notification systems (console, email, file)utils/format.go
: Message formatting utilities
weatherReport.txt
: Continuous log of weather data and alerts- Email notifications: Sent to configured recipient
go build ./cmd/weather-alert
go test ./...
- Modify
alert/alert.go
to add new condition logic - Update
utils/format.go
for new message formats - Test with your local weather conditions
- Verify Gmail App Password is correct
- Check if 2FA is enabled on Gmail account
- Ensure firewall allows outbound SMTP connections
- Try different SMTP ports (587 or 465)
- Verify WeatherAPI key is valid and not expired
- Check city name spelling
- Ensure internet connectivity
- Adjust alert thresholds in
alert/alert.go
- Increase monitoring interval
- Check if weather conditions are genuinely extreme
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature
) - Commit changes (
git commit -am 'Add new feature'
) - Push to branch (
git push origin feature/new-feature
) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- WeatherAPI for weather data
- godotenv for environment configuration
- Go community for excellent libraries and documentation
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Review your
.env
configuration - Open an issue on GitHub with detailed error messages
Happy Weather Monitoring! π¦οΈ