A Python-based command-line application to fetch and display weather information for a city using the OpenWeatherMap API. The application allows users to choose between viewing the current weather and a 5-day forecast.
- Fetch current weather data for a specified city.
- Fetch 5-day weather forecast data for a specified city.
- Display weather information in both metric and imperial units.
- Interactive menu for selecting the type of weather information to display.
- Python 3.6 or higher
- OpenWeatherMap API key
-
Clone the repository or download the script.
-
Install the required Python packages using pip:
pip install -r requirements.txt
-
Create a
settings.ini
file in the same directory as the script and add your OpenWeatherMap API key:[openweather] api_key = your_api_key_here
Run the script from the command line with the required arguments.
city
(required): The name of the city for which you want to fetch the weather data.-i
,--imperial
(optional): Display the temperature in imperial units (Fahrenheit).
To get the current weather for London in metric units:
python app.py London
To get the current weather for New York in imperial units:
python app.py New York -i
After running the script, you will be presented with a menu to choose between viewing the current weather or the 5-day forecast:
Choose an option:
1. Current Weather
2. 5-Day Forecast
3. Exit
Enter your choice (1/2/3):
Enter 1
to view the current weather, 2
to view the 5-day forecast, or 3
to exit the program.
Reads the API key from the settings.ini
file.
Parses command-line arguments.
Builds the query URL for the OpenWeatherMap API.
Fetches weather data from the OpenWeatherMap API.
Displays the current weather data.
Displays the 5-day weather forecast data.
This project is licensed under the MIT License. See the LICENSE file for details.
Make sure to replace your_api_key_here
with your actual OpenWeatherMap API key when running the script.