This project implements a backend for a weather notification service using Flask and Socket.IO, demonstrating the Observer Pattern in software design.
models/
: Contains the Observer and Subject classes for implementing the Observer Pattern.observer.py
: Defines the baseObserver
class.rain_observer.py
: ExtendsObserver
to react specifically to rain alerts.subject.py
: Implements theSubject
class to manage observers.
routes/
: Flask routes for subscribing and unsubscribing to weather alerts.subscription.py
: Handles subscription management.
utils/
: Utility scripts and configurations.socketio.py
: Configures Socket.IO for real-time web communication.weather.py
: Contains the logic to check current weather conditions using the OpenWeather API.
- Install dependencies:
pip install -r requirements.txt
- Set up your OpenWeather API key in
utils/weather.py
. - Run the backend server:
python main.py
- Subscribe to alerts: Send a POST request to
/api/subscribe
with an observer ID and alert type. - Unsubscribe from alerts: Send a POST request to
/api/unsubscribe
with the observer ID. - Trigger weather check: Access
/api/notify
to manually trigger a check for current weather conditions.
This backend is designed to work seamlessly with its React Native front-end counterpart, which provides a user interface for subscribing to weather alerts and receiving real-time notifications. The front-end application utilizes Socket.IO for real-time communication with this backend, demonstrating a complete system that leverages the Observer Pattern for delivering weather updates to users.
Check out the front-end project here: Weather App Front-end
Contributions to the project are welcome! Please feel free to fork the repository, make your changes, and submit a pull request.
This project is open-sourced under the MIT License.