This Python script leverages various APIs and libraries to provide real-time weather information and send alerts using Twilio. Here's a breakdown of the key components and functions in your code:
This program fetches weather data for a specific city (in this case, Coral Gables) from the OpenWeatherMap API and then sends a weather alert via Twilio SMS. It provides essential weather information such as temperature, humidity, wind speed, and sunrise/sunset times.
This function converts temperature from Kelvin to Celsius and Fahrenheit.
This function converts wind speed from meters per second to miles per hour and kilometers per hour.
This function sends a weather alert message using Twilio. It reads account SID, authentication token, and phone numbers from external files.
The main()
function is the entry point of the program. It fetches weather data from the OpenWeatherMap API, processes the data, and then sends the weather alert via Twilio using the send_weather_alert()
function.
To use this program effectively, follow these steps:
- Ensure you have the necessary API keys and credentials.
- Customize the city by modifying the
CITY
variable in the script. - Prepare the required configuration files (
api_key.txt
,account_sid.txt
,auth_token.txt
,twilio_phone_number.txt
, andmy_phone_number.txt
) with your specific values. - Run the script, and you will receive a weather alert SMS with the current weather conditions.
Before running the program, make sure to configure the following files with the appropriate values:
api_key.txt
: Your OpenWeatherMap API key.account_sid.txt
andauth_token.txt
: Twilio account SID and authentication token.twilio_phone_number.txt
: Your Twilio phone number.my_phone_number.txt
: The recipient phone number for the weather alert.
This program makes use of the following libraries and APIs:
- OpenWeatherMap API: For weather data retrieval.
- Twilio: For sending SMS alerts.
Feel free to enhance it further or adapt it for other use cases. If you have any questions or need assistance, don't hesitate to reach out. Happy coding! 🌦️📲