A Python-based AWS Lambda function that generates weather reports for NFL games and automatically tweets them using the Twitter API. This project leverages the nfl_data_py library for NFL schedules, the OpenWeather API for weather data, and AWS Lambda for serverless deployment.
- Fetches up-to-date NFL schedules using
nfl_data_py. - Retrieves accurate weather data for NFL game locations using the OpenWeather API.
- Automatically generates and posts weather reports for NFL games to Twitter.
- Configured for AWS Lambda with Python 3.12 runtime and arm64 architecture.
- Uses an AWS Lambda layer for efficient handling of
numpyandpandas. - Supports AWS EventBridge Schedule (Cron) for automatic invocation.
- Python 3.12
- AWS account with permissions to create Lambda functions and layers
- Twitter Developer account for API keys
- OpenWeather API key
git clone https://github.com/<your-username>/NFL-weather-bot.git
cd NFL-weather-bot- WEATHER_API_KEY: Your OpenWeather API key.
- API_KEY: Twitter API key.
- API_KEY_SECRET: Twitter API key secret.
- BEARER_TOKEN: Twitter Bearer token.
- ACCESS_TOKEN: Twitter access token.
- ACCESS_TOKEN_SECRET: Twitter access token secret.
- Create a virtual environment:
python3 -m venv venv source venv/bin/activate - Install required dependencies:
pip install -r requirements.txt -t . - Remove numpy and pandas directories (these will be provided via a Lambda layer):
rm -rf numpy* rm -rf pandas*
- Zip the application and dependencies:
zip -r lambda_deployment.zip . - Add the main application file:
zip -g lambda_deployment.zip app.py
-
Log in to the AWS Lambda Console and create a new function.
-
Set the runtime to Python 3.12 and architecture to arm64.
-
Upload the lambda_deployment.zip file as the function code.
-
Attach the AWS Lambda layer for numpy and pandas:
arn:aws:lambda:<region>:724772057174:layer:Python312-Numpy-Pandas:1
-
Add the environment variables under the Configuration tab.
Run the script locally for testing:
python app.pyThe script will generate weather reports for NFL games on a specified day (e.g., Thursday) and print them to the console (you can uncomment the "twitter_client = twitter_api_setup()" and "twitter_client.create_tweet(text=item)" lines to also post the tweets manually)
Set up an EventBridge rule or manually trigger the function with the following sample event:
{
"day_of_week": "Thursday"
}The Lambda function will:
- Fetch the schedule for the specified day.
- Generate weather reports.
- Tweet the reports via the configured Twitter account.
- Go to the AWS EventBridge Console and create a new rule.
- Choose Event Source → Schedule.
- Use a Cron Expression to define the schedule for invoking the function:
- Example (Every Thursday at 10:00 AM UTC):
0 10 ? * 5 *
- Set the target to your deployed Lambda function.
- Save the rule, and your function will now automatically run as scheduled.
- The main script that handles:
- Fetching NFL schedules.
- Retrieving weather data for game locations.
- Generating formatted weather reports.
- Posting tweets via the Twitter API.
- Contains the list of Python dependencies: requests nfl_data_py tweepy pytz datetime
- NFL Schedules: Pulled using nfl_data_py.
- Weather Data: Retrieved for each stadium using the OpenWeather API.
- Twitter Integration: Posts game-specific weather updates to a Twitter account.
This project is licensed under the MIT License. See the LICENSE file for more details.
Feel free to submit issues or pull requests to improve this project. Contributions are welcome!