Automated Weather Forecasting & Alert System for South Bend, Indiana
WeatherBot is a robust Python application designed to provide real-time weather updates and severe weather alerts via Twitter (X). Leveraging the National Weather Service (NWS) API, it ensures the community stays informed with accurate, timely, and automated broadcasts.
Live at https://x.com/SBforecast
- Scheduled Forecasts: Automatically tweets current conditions and short-term forecasts five times daily (3 AM, 7 AM, 12 PM, 5 PM, and 10 PM).
- Real-Time Alerts: Monitors NWS feeds every 5 minutes to broadcast severe weather warnings immediately.
- Smart Caching: Implements a caching mechanism to prevent duplicate alerts for the same weather event.
- Resilient Architecture: Built with
apschedulerfor reliable task scheduling and error handling for network requests. - Live Data: Fetches precise, localized data directly from
api.weather.gov.
- Language: Python 3.11+
- APIs:
- National Weather Service API (Weather Data)
- Twitter API v2 (Broadcasting)
- Key Libraries:
requests&requests-oauthlib: HTTP networking and OAuth authentication.apscheduler: Advanced background scheduling.flask: Lightweight web server (required for cloud hosting health checks).python-dotenv: Environment variable management.
The application requires the following environment variables to function. These can be set in a .env file for local development or in your cloud provider's dashboard.
| Variable | Description | Default / Example |
|---|---|---|
CITY |
Target city name for display | South Bend, Indiana |
LAT |
Latitude of the location | 41.6764 |
LON |
Longitude of the location | -86.2520 |
TWITTER_API_KEY |
Twitter Consumer Key | ... |
TWITTER_API_SECRET |
Twitter Consumer Secret | ... |
TWITTER_ACCESS_TOKEN |
Twitter Access Token | ... |
TWITTER_ACCESS_TOKEN_SECRET |
Twitter Access Token Secret | ... |
To run WeatherBot locally on your machine:
-
Clone the repository
git clone https://github.com/yourusername/weatherbot.git cd weatherbot -
Install dependencies
pip install -r requirements.txt
-
Configure Environment Create a
.envfile in the root directory and add your API keys (see Configuration). -
Run the Bot
python weatherbot.py
The bot will start a local web server at
http://localhost:5000and begin its scheduling loop.
This project is optimized for deployment on Render as a Web Service (Free Tier compatible).
- Push to GitHub: Ensure your code is in a GitHub repository.
- New Blueprint: Go to the Render Dashboard, click New, and select Blueprint.
- Connect Repo: Select your
weatherbotrepository. - Auto-Configuration: Render will detect the
render.yamlfile included in this project. - Credentials: You will be prompted to input your Twitter API credentials securely during the setup.
- Launch: Click Apply. Render will build the environment and start the web service.
The service is configured to run continuously. Render will ping the web server to keep it alive.
Developed by [Your Name]