Skip to content

riyagoyal01/Weather-CLI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌤️ Weather CLI

A Python command-line application that fetches real-time weather data for any city worldwide, with built-in search history management.


📌 Overview

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.


✨ Features

  • 🔍 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.json file
  • 🗑️ 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

🛠️ Tech Stack

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

📂 Project Structure

Weather-CLI/
│
├── main.py             # Main application logic
├── requirements.txt    # Python dependencies
├── history.json        # Auto-generated search history (gitignored)
├── .gitignore
└── README.md

🚀 Getting Started

Prerequisites

Installation

1. Clone the repository

git clone https://github.com/riyagoyal01/Weather-CLI.git
cd Weather-CLI

2. Install dependencies

pip install -r requirements.txt

3. 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_here

4. Run the application

python main.py

💻 Usage

Once 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

📊 How It Works

User Input (City Name)
        │
        ▼
  Fetch API Key from Environment
        │
        ▼
  HTTP GET → OpenWeatherMap API
        │
        ├── Success → Display weather + Save to history.json
        │
        └── Failure → Show error message

About

A Python CLI tool that fetches and displays current weather data for a given city using an external API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages