A Python command-line application that fetches real-time weather data for any city worldwide, with built-in search history management.
Weather CLI is a lightweight terminal-based weather tool built with Python. It integrates with the OpenWeatherMap API to retrieve live weather conditions and stores your search history locally in JSON format — no database required.
This project demonstrates core Python skills including REST API consumption, environment variable management, file I/O, JSON handling, and building interactive CLI menus.
- 🔍 Real-time Weather Search — Fetch current weather for any city globally
- 🌡️ Detailed Metrics — Displays temperature (current, max, min), humidity, and weather description
- 📁 Persistent Search History — Saves past searches to a local
history.jsonfile - 🗑️ History Management — View or clear your past searches anytime
- 🔐 Secure API Key Handling — Reads API key from environment variable (no hardcoding)
⚠️ Error Handling — Handles invalid city names and missing API keys gracefully
| Technology | Purpose |
|---|---|
| Python 3 | Core language |
requests |
HTTP API calls |
json |
History file storage |
os |
Environment variable access |
datetime |
Timestamping search history |
| OpenWeatherMap API | Live weather data source |
Weather-CLI/
│
├── main.py # Main application logic
├── requirements.txt # Python dependencies
├── history.json # Auto-generated search history (gitignored)
├── .gitignore
└── README.md
- Python 3.7+
- A free OpenWeatherMap API key
1. Clone the repository
git clone https://github.com/riyagoyal01/Weather-CLI.git
cd Weather-CLI2. Install dependencies
pip install -r requirements.txt3. Set your API key as an environment variable
On macOS/Linux:
export OPENWEATHER_API_KEY="your_api_key_here"On Windows (Command Prompt):
set OPENWEATHER_API_KEY=your_api_key_here4. Run the application
python main.pyOnce launched, you'll see an interactive menu:
-------------- Weather App ---------------
1. Search Weather in a City
2. Show Search History
3. Clear History
4. Exit
Enter your Choice:
Example — Searching weather for Mumbai:
Enter city name: mumbai
Weather Report for Mumbai
Max/Min Temperature: 34°C/27°C
Temperature: 31°C
Humidity: 72 %
Weather: broken clouds
User Input (City Name)
│
▼
Fetch API Key from Environment
│
▼
HTTP GET → OpenWeatherMap API
│
├── Success → Display weather + Save to history.json
│
└── Failure → Show error message