The Weather Forecasting Tool is a command line application that provides users with the current weather forecast for a given city. It leverages the OpenWeatherMap API to fetch weather data and parse it using Python. This tool demonstrates the usage of the OpenWeatherMap API, data parsing, and error handling.
wea.mp4
The web application for the Weather Forecasting Tool can be accessed at http://rudra26.pythonanywhere.com/ . It provides a user-friendly interface to enter the city name and fetch the weather forecast. The web page displays the weather information for the specified city, including weather description, temperature, minimum temperature, maximum temperature, and humidity.
The Weather Forecasting Tool follows a simple architectural flow to fetch and display weather data. The main components of the application are as follows:
-
User Input:
- The user is prompted to enter the name of the city for which they want to fetch the weather forecast.
-
API Request:
- The user's input is used to construct a URL with the OpenWeatherMap API endpoint and the API key.
- A GET request is sent to the API endpoint using the constructed URL.
- The API response is received and processed.
-
Response Handling:
- The response is checked for errors and appropriate error handling is performed.
- If the response is successful, the JSON data is extracted from the response.
-
Data Parsing:
- The JSON data is parsed to extract the required weather information such as temperature, humidity, pressure, etc.
-
Display:
- The extracted weather information is displayed to the user on the command line.
The Weather Forecasting Tool incorporates error handling to handle potential issues during the API request, response handling, and data parsing stages. The following errors are specifically handled:
- Connection errors: Handles cases where there is no internet connection or connection timeouts.
- Invalid API key: Detects and informs the user if the API key used is invalid.
- City not found: Handles cases when the provided city name is not found in the API response.
- JSON decoding errors: Catches errors that may occur during JSON decoding of the API response.
The Weather Forecasting Tool requires the following dependencies:
- Python 3.8
- requests library: Used for making HTTP requests to the OpenWeatherMap API.
- json library: Used for JSON parsing and decoding.
To use the Weather Forecasting Tool, follow these steps:
- Install Python 3.x if not already installed.
- Install the requests library by running the command:
pip install requests
. - Clone the repository and navigate to the project directory.
- Run the
weather.py
file. - Enter the name of the city for which you want to fetch the weather forecast.
- The tool will display the current weather information for the specified city.
Note: Ensure you have a valid API key from OpenWeatherMap and replace the placeholder API key in the code with your own key.
Contributions to the Weather Forecasting Tool are welcome. If you encounter any issues or have suggestions for improvements, please feel free to submit a pull request or open an issue on the project repository.
The Weather Forecasting Tool is released under the MIT License. See the LICENSE
file for more details.