A command-line weather app built with Python that fetches real-time weather data from the OpenWeatherMap API.
- Current temperature and feels-like temperature
- Humidity, wind speed, and visibility
- Handles invalid city names gracefully
- Handles no internet connection gracefully
- API key stored securely in .env file
- Python 3.14
- requests
- python-decouple
- Clone the repository
git clone https://github.com/wasir-codes/fullstack-journey.git
cd week-05-06/weather_cli- Create and activate virtual environment
python -m venv venv
venv\Scripts\activate- Install dependencies
pip install -r requirements.txt-
Get a free API key from https://openweathermap.org
-
Create a .env file in the project root
Write this line with your api key in the .env file:
API_KEY=your_api_key_here- Run the app
python weather.py📍 Dhaka, BD 🌤 Overcast clouds 🌡 Temperature : 24.98°C (feels like 25.73°C) 💧 Humidity : 84% 💨 Wind speed : 2.2 m/s 👁 Visibility : 10.0 km
- How to use the requests library to call the OpenWeatherMap API, parse the JSON response, and extract nested fields like data['main']['temp'] and data['weather'][0]['description']
- Handling multiple error cases as required - in this app (invalid city, no internet, timeout)
- Learned why timeout=5 matters - without it, a slow server can hang your program indefinitely
- Storing secrets securely using .env and python decouple
- Setting up virtual environment(venv)