Skip to content

ishworii/weather_cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Weather CLI

A command-line weather application built with Rust that fetches and displays current weather conditions and forecasts for any location using the Visual Crossing Weather API.

Features

  • Fetch current weather conditions with real-time data
  • Display detailed forecast for today and tomorrow
  • Clean, formatted output with temperature (Fahrenheit), humidity, conditions, and descriptions
  • Support for any location worldwide
  • Environment variable configuration for API key
  • Automatic timezone handling for accurate local dates and times

Prerequisites

  • Rust 1.70 or higher
  • Visual Crossing Weather API key (get one free at visualcrossing.com)

Installation

  1. Clone the repository:
git clone git@github.com:ishworii/weather_cli.git
cd weather_cli
  1. Create a .env file in the project root:
echo "API_KEY=your_api_key_here" > .env
  1. Build the project:
cargo build --release

Usage

Run the application with a location as an argument:

cargo run -- <location>

Examples

# Get weather for Kathmandu
cargo run -- Kathmandu

# Get weather for New York
cargo run -- "New York"

# Get weather for London
cargo run -- London

Output Example

╔══════════════════════════════════════════════════════════╗
║               CURRENT WEATHER CONDITIONS                 ║
╚══════════════════════════════════════════════════════════╝
Date: 2025-10-10 (Time: 18:30:00)
Temperature: 75.8°F
Humidity: 88.6%
Conditions: Partially cloudy


╔══════════════════════════════════════════════════════════╗
║                  FORECAST FOR TODAY                      ║
╚══════════════════════════════════════════════════════════╝
Date: 2025-10-10
Temperature: 78.0°F
High/Low: 80.1°F / 75.3°F
Humidity: 90.9%
Conditions: Rain, Partially cloudy
Description: Partly cloudy throughout the day with storms possible.

╔══════════════════════════════════════════════════════════╗
║                 FORECAST FOR TOMORROW                    ║
╚══════════════════════════════════════════════════════════╝
Date: 2025-10-11
Temperature: 79.8°F
High/Low: 83.0°F / 76.9°F
Humidity: 86.2%
Conditions: Rain, Partially cloudy
Description: Partly cloudy throughout the day with storms possible.

Project Structure

weather_cli/
├── src/
│   ├── main.rs       # Entry point and CLI parsing
│   ├── lib.rs        # Main application logic
│   ├── api.rs        # API client implementation
│   ├── config.rs     # Configuration management
│   └── weather.rs    # Weather data structures and Display trait
├── Cargo.toml
├── .env              # API key (not committed)
└── README.md

Dependencies

  • reqwest - HTTP client for API requests
  • tokio - Async runtime
  • serde / serde_json - JSON serialization/deserialization
  • clap - Command-line argument parsing
  • dotenvy - Environment variable management
  • chrono - Date and time handling

Configuration

The application requires an API key from Visual Crossing Weather API. Set it in a .env file:

API_KEY=your_api_key_here

Error Handling

The application handles common errors such as:

  • Invalid API key
  • Network connectivity issues
  • Invalid location names
  • JSON parsing errors

License

This project is available under the MIT License.

About

A cli tool for weather forecast of a city

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages