This is a simple command-line application that retrieves weather information using the OpenWeatherMap API. The program allows users to get weather details by providing a ZIP code, city and state, or geographic coordinates (latitude and longitude). The results include temperature, humidity, weather description, and more.
- Get current weather by ZIP code
- Get current weather by geographic coordinates (latitude and longitude)
- Get current weather by city and state
- Clear console between actions for better readability
- Simple text-based menu for easy navigation
- Python 3.x
requestslibrary (You can install it viapip install requests)
-
Clone this repository:
git clone https://github.com/demurestpie/weather-cli.git cd weather-cli -
Install dependencies:
pip install requests
-
Obtain an API key from OpenWeatherMap.
-
Set the
API_KEYin the .env file to your OpenWeatherMap API key.API_KEY = "your_openweathermap_api_key"
-
Run the program:
python weather.py
- Units for Temperature: The temperature is displayed in Fahrenheit (
imperialunits). You can modify theunitsvariable in the code tometric(Celsius) orstandard(Kelvin) if needed. - Country Code: The default country code is set to
"US". You can change this if you need weather for cities in other countries.
- Select the option
1from the menu. - Enter a valid ZIP code (e.g.,
37601). - The program will display the weather details for the location associated with that ZIP code.
- Select the option
2from the menu. - Enter the latitude and longitude values for the location (e.g.,
36.3134,-82.3535). - The program will retrieve and display the weather for those geographic coordinates.
- Select the option
3from the menu. - Enter the city name and state abbreviation (e.g.,
Johnson City,TN). - The program will fetch the weather details for that city.
- Choose option
4to exit the program.
- The program handles invalid inputs (e.g., non-numeric ZIP codes or coordinates).
- If the weather data cannot be retrieved due to a network error or invalid API key, the program will display the relevant HTTP status code and error message.