Skip to content

A real-time weather monitoring and alerting service built in Go that keeps you informed about weather conditions based on your customizable thresholds.

License

Notifications You must be signed in to change notification settings

Trynax/WeatherWatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WeatherWatch 🌦️

A real-time weather monitoring and alerting system built in Go that tracks weather conditions and sends notifications when specified thresholds are exceeded.

Features ✨

  • 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

Project Structure πŸ“

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

Prerequisites πŸ“‹

  • Go 1.19 or higher
  • WeatherAPI account (free tier available)
  • Gmail account with App Password (for email notifications)

Installation & Setup πŸš€

1. Clone the Repository

git clone https://github.com/yourusername/WeatherWatch.git
cd WeatherWatch

2. Install Dependencies

go mod tidy

3. Environment Configuration

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"

4. Get WeatherAPI Key

  1. Visit WeatherAPI.com
  2. Sign up for a free account
  3. Copy your API key to the .env file

5. Setup Gmail App Password

  1. Enable 2-Factor Authentication on your Gmail account
  2. Go to Google Account Settings β†’ Security β†’ App Passwords
  3. Generate a new app password
  4. Use this password in your .env file (not your regular Gmail password)

Usage πŸ’»

Basic Usage

Run the weather monitoring system:

make run

Or directly with Go:

go run ./cmd/weather-alert/main.go

Customization

Change Monitoring Location

Edit cmd/weather-alert/main.go:

scheduler.CheckWeatherOnSchedule(1, "Lagos")  // Change "Lagos" to your city

Adjust Monitoring Interval

scheduler.CheckWeatherOnSchedule(5, "Lagos")  // Check every 5 minutes

Customize Alert Thresholds

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
)

Alert Conditions 🚨

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

Output Examples πŸ“Š

Console Output

πŸ“ 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%

Alert Example

⚠️ ALERTS Triggered
πŸ“ Lagos, Nigeria | πŸ•’ 2025-07-13 00:00
---------------------------------
🌬️ High Wind Speed: 26.6 kph (threshold: 22.3 kph)

File Structure Details πŸ“‹

Core Components

  • cmd/weather-alert/main.go: Application entry point
  • scheduler/scheduler.go: Main monitoring loop with signal handling
  • api/weatherapi.go: WeatherAPI client and data structures
  • alert/alert.go: Alert condition checking logic
  • notify/: Notification systems (console, email, file)
  • utils/format.go: Message formatting utilities

Generated Files

  • weatherReport.txt: Continuous log of weather data and alerts
  • Email notifications: Sent to configured recipient

Development πŸ› οΈ

Build the Project

go build ./cmd/weather-alert

Run Tests

go test ./...

Add New Alert Conditions

  1. Modify alert/alert.go to add new condition logic
  2. Update utils/format.go for new message formats
  3. Test with your local weather conditions

Troubleshooting πŸ”§

Email Not Sending

  • 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)

API Errors

  • Verify WeatherAPI key is valid and not expired
  • Check city name spelling
  • Ensure internet connectivity

High Alert Frequency

  • Adjust alert thresholds in alert/alert.go
  • Increase monitoring interval
  • Check if weather conditions are genuinely extreme

Contributing 🀝

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-feature)
  3. Commit changes (git commit -am 'Add new feature')
  4. Push to branch (git push origin feature/new-feature)
  5. Create a Pull Request

License πŸ“

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments πŸ™

  • WeatherAPI for weather data
  • godotenv for environment configuration
  • Go community for excellent libraries and documentation

Support πŸ’¬

If you encounter any issues or have questions:

  1. Check the troubleshooting section above
  2. Review your .env configuration
  3. Open an issue on GitHub with detailed error messages

Happy Weather Monitoring! 🌦️

About

A real-time weather monitoring and alerting service built in Go that keeps you informed about weather conditions based on your customizable thresholds.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published