A concise and functional application built entirely in Python to fetch and display real-time weather data for any major city worldwide.
This project demonstrates core programming concepts including API integration, data parsing (JSON), and error handling, making it a complete portfolio piece.
- Real-time Data: Fetches up-to-the-minute weather conditions directly from the OpenWeatherMap API.
- Detailed Metrics: Displays key weather metrics, including:
- Current Temperature
- 'Feels Like' Temperature
- Humidity
- Atmospheric Pressure
- Weather Description (e.g., "clear sky," "broken clouds")
- Interactive CLI: Simple command-line interface (CLI) that prompts the user for a city name and runs continuously until the user types 'exit'.
- Error Handling: Includes checks for API connection errors and user input errors (e.g., city not found).
| Technology | Purpose |
|---|---|
| Python 3 | Core language for the application logic. |
requests |
Library used to make HTTP requests to the external API. |
| OpenWeatherMap API | The free web service providing the weather data. |
| JSON | Data format used for receiving and parsing information from the API. |
Follow these steps to run the application on your local machine.
You must have Python 3 installed and the requests library.
# Install the necessary Python library
pip install requestsYou need a free API key from OpenWeatherMap:
-
Sign up for an account at OpenWeatherMap.
-
Navigate to the "My API Keys" section to find your key.
-
Open the
weather_app.pyfile and replace the placeholder text with your actual key:# IMPORTANT: Replace 'YOUR_API_KEY' with your actual API key! API_KEY = "YOUR_API_KEY"
Execute the Python script from your terminal:
python weather_app.pyThe application will launch and prompt you to enter a city name:
Enter city name (or 'exit' to quit): Paris, France
--- Weather in Paris, France ---
Temperature: 15.2°C
Feels Like: 14.8°C
Humidity: 78%
Pressure: 1012 hPa
Description: Overcast clouds
--------------------------
Enter city name (or 'exit' to quit):