A simple command-line app that fetches current weather for any city using the OpenWeatherMap API.
- Get real-time temperature, "feels like", humidity, wind speed, and weather condition for any city
- Metric units (°C, m/s)
- Handles common errors: invalid API key, city not found, timeouts, connection issues
.
├── main.py # App entry point
├── api_key # Your OpenWeatherMap API key (plain text)
├── README.md
└── LICENSE
-
Get an API key Sign up at openweathermap.org and grab a free API key.
-
Add your API key Paste your api key in the
api_keyfile (no quotes, no extra whitespace):your_api_key_here -
Install dependencies
pip install requests
Run the app:
python main.pyYou'll be prompted to enter a city name:
Enter a city: London
========================================
WEATHER IN LONDON
========================================
🌡️ Temperature : 18.2°C
🤔 Feels Like : 17.9°C
💧 Humidity : 64%
💨 Wind Speed : 3.6 m/s
☁️ Condition : Scattered clouds
========================================
| Scenario | Message |
|---|---|
| Empty city input | Error: City name cannot be empty. |
| Invalid API key | Error: Invalid API key. |
| City not found | Error: City '<city>' was not found. |
| Request timeout | Error: Request timed out. |
| Connection failure | Error: Could not connect to the server. |
| Other HTTP errors | Error: Server returned status code <code>. |
- Keep your
api_keyfile private — don't commit it to version control. Add it to.gitignore. - Temperature units are set to metric (Celsius) by default. Change
unitsinmain.pytoimperialfor Fahrenheit.
See LICENSE for details.