Skip to main content

A fast, feature-rich command-line weather tool

Project description

Weather CLI

A simple, fast, and feature-rich command-line weather tool with multiple data sources and output formats.

Features

  • ๐ŸŒ Multiple location input types: City names, ZIP codes, coordinates (decimal & DMS), auto-detection
  • ๐Ÿ“Š Multiple output formats: Simple, visual, raw JSON
  • ๐Ÿ“ Unit systems: Metric and Imperial units
  • ๐Ÿƒโ€โ™‚๏ธ Fast and lightweight: Minimal dependencies, quick responses
  • ๐Ÿ’พ Smart caching: 5-minute cache to reduce API calls
  • ๐ŸŒ Multiple data sources: Open-Meteo (implemented), wttr.in and NWS (planned)
  • โš™๏ธ Configurable: Config file and command-line options

Installation

# Clone the repository
git clone https://github.com/mikebc23/weather-cli.git
cd weather-cli

# Install in development mode
pip install -e .

# Or install from source
pip install .

Quick Start

# Current location (auto-detect via IP)
weather

# City names
weather "New York"
weather "San Josรฉ, Costa Rica"
weather "Tokyo"

# Coordinates
weather "40.7128,-74.0060"           # NYC
weather "9.9281,-84.0907"            # San Josรฉ, CR
weather --lat=51.5074 --lon=-0.1278  # London

# Different output formats
weather "Tokyo" --format=visual
weather "London" --format=simple --units=imperial
weather "NYC" --format=raw        # JSON output

Output Formats

Simple (default)

San Josรฉ, CR: 22ยฐC, Partly Cloudy
Feels like: 25ยฐC | Humidity: 65% | Wind: 8 km/h

Visual

San Josรฉ, CR
     \   /     22ยฐC
      .-.      Partly Cloudy
   โ€• (   ) โ€•   โ†— 8 km/h
      `-'      65% humidity
     /   \

Raw JSON

{
  "location": {
    "name": "San Josรฉ, Costa Rica",
    "latitude": 9.9281,
    "longitude": -84.0907,
    "country": "Costa Rica"
  },
  "current": {
    "temperature_2m": 22.5,
    "relative_humidity_2m": 65,
    "apparent_temperature": 25.1,
    "wind_speed_10m": 8.2,
    "condition": "Partly cloudy",
    "pressure_msl": 1013.2,
    "cloud_cover": 25,
    "uv_index": 3.2
  },
  "units": {
    "temperature": "ยฐC",
    "wind_speed": "km/h",
    "pressure": "hPa"
  },
  "source": "open-meteo",
  "timestamp": "2025-07-14T15:30:00Z",
  "cache_hit": false
}

Command Line Options

weather [location] [options]

Positional Arguments:
  location              Location (city, ZIP code, coordinates, or auto-detect)

Location Options:
  --lat LAT             Latitude (use with --lon)
  --lon LON             Longitude (use with --lat)

Format Options:
  --format FORMAT       Output format: simple, visual, raw (default: simple)
  --units UNITS         Unit system: metric, imperial (default: metric)

Data Source Options:
  --source SOURCE       Weather source: open-meteo, wttr, nws (default: open-meteo)
  --timeout TIMEOUT     HTTP timeout in seconds (default: 10)

Cache Options:
  --no-cache            Disable cache usage
  --clear-cache         Clear cache and exit

Other Options:
  --config CONFIG       Path to configuration file
  --debug               Enable debug output
  --version             Show version
  --help                Show help message

Configuration

The tool uses a configuration file at ~/.weather.conf (JSON format):

{
  "units": "metric",
  "format": "simple",
  "source": "open-meteo",
  "cache_duration": 300,
  "timeout": 10
}

Supported Location Formats

Format Example Description
Auto-detect weather Uses IP geolocation
City name "New York" City, country, or address
ZIP code "10001" US ZIP codes (5 or 9 digits)
Decimal coordinates "40.7128,-74.0060" Latitude,longitude
Explicit coordinates --lat=40.7128 --lon=-74.0060 Separate lat/lon flags
DMS coordinates "40ยฐ42'46.0\"N 74ยฐ00'21.6\"W" Degrees, minutes, seconds

Project Structure

weather-cli/
โ”œโ”€โ”€ weather/                 # Main package
โ”‚   โ”œโ”€โ”€ main.py              # CLI entry point
โ”‚   โ”œโ”€โ”€ config.py            # Configuration management
โ”‚   โ”œโ”€โ”€ cache.py             # Caching system
โ”‚   โ”œโ”€โ”€ location.py          # Location services (geocoding)
โ”‚   โ”œโ”€โ”€ sources/             # Weather data sources
โ”‚   โ”‚   โ”œโ”€โ”€ base.py          # Abstract base class
โ”‚   โ”‚   โ”œโ”€โ”€ open_meteo.py    # Open-Meteo API
โ”‚   โ”‚   โ”œโ”€โ”€ wttr.py          # wttr.in service
โ”‚   โ”‚   โ””โ”€โ”€ nws.py           # National Weather Service
โ”‚   โ”œโ”€โ”€ formatters/          # Output formatters
โ”‚   โ”‚   โ”œโ”€โ”€ base.py          # Abstract formatter
โ”‚   โ”‚   โ”œโ”€โ”€ simple.py        # Simple text output
โ”‚   โ”‚   โ”œโ”€โ”€ visual.py        # Visual ASCII art format
โ”‚   โ”‚   โ””โ”€โ”€ raw.py           # Raw JSON output
โ”‚   โ””โ”€โ”€ utils/               # Utility functions
โ”‚       โ”œโ”€โ”€ http.py          # HTTP client wrapper
โ”‚       โ”œโ”€โ”€ units.py         # Unit conversions
โ”‚       โ””โ”€โ”€ exceptions.py    # Custom exceptions
โ”œโ”€โ”€ tests/                   # Test suite
โ”‚   โ”œโ”€โ”€ conftest.py          # pytest fixtures
โ”‚   โ””โ”€โ”€ test_location.py     # Location tests
โ”œโ”€โ”€ setup.py                 # Package setup
โ”œโ”€โ”€ requirements.txt         # Dependencies
โ””โ”€โ”€ README.md                # This file

Data Sources

Open-Meteo (Primary)

  • Status: Implemented and working
  • Coverage: Global
  • Features: Current weather, forecasts, no API key required
  • Rate limit: Generous free tier
  • URL: https://open-meteo.com/

wttr.in (Planned)

  • Status: Placeholder implemented
  • Coverage: Global
  • Features: Simple curl-based service, ASCII art built-in
  • Rate limit: Fair use

National Weather Service (Planned)

  • Status: Placeholder implemented
  • Coverage: United States only
  • Features: Official US government weather data
  • Rate limit: None (government API)

Dependencies

  • requests>=2.25.0 - HTTP requests
  • urllib3>=1.26.0 - HTTP client utilities

Development dependencies:

  • pytest - Testing framework

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=weather

# Run specific test file
pytest tests/test_location.py -v

Examples

# Different locations
weather                                   # Auto-detect
weather "Paris, France"                   # City name
weather "90210"                           # ZIP code
weather "35.6762,139.6503"                # Tokyo coordinates

# Different formats and units
weather "London" --format=visual --units=imperial
weather "Moscow" --format=simple --units=metric
weather "Sydney" --format=raw             # JSON output

# Using explicit coordinates
weather --lat=55.7558 --lon=37.6173       # Moscow
weather --lat=-33.8688 --lon=151.2093     # Sydney

# Configuration and caching
weather "NYC" --no-cache                  # Skip cache
weather --clear-cache                     # Clear cache
weather "NYC" --timeout=5                 # Custom timeout

Error Handling

The tool provides clear error messages for common issues:

  • Location not found: "Location error: Place not found: Invalid City"
  • Invalid coordinates: "Location error: Invalid latitude: 91.0. Must be between -90 and 90"
  • Network issues: "Weather data error: Failed to get weather from Open-Meteo: Connection timeout"
  • Invalid format: "Error: Unknown format: badformat"

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for your changes
  5. Run tests (pytest)
  6. Commit your changes (git commit -am 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cr_mb_weather_cli-1.0.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cr_mb_weather_cli-1.0.0-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file cr_mb_weather_cli-1.0.0.tar.gz.

File metadata

  • Download URL: cr_mb_weather_cli-1.0.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for cr_mb_weather_cli-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d35cacd01bc8220078946f5803863940d612188fccecff35fd73074022c249fc
MD5 29fff645ce902747a051283fab13a8d4
BLAKE2b-256 cfded728009aa453111cc8345c4d24d0ff9f4d01cfdde5f4dcb302227e0bf551

See more details on using hashes here.

File details

Details for the file cr_mb_weather_cli-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cr_mb_weather_cli-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26c1b72216bf14d9c8648c31273c304917955846781180cd5d8c6455a7ddc6ef
MD5 b7fc9adb9256fb13141e720d10db2c98
BLAKE2b-256 731ff8761e783ec4876617ac17029d98dce78c53975bbc9391190b78ac04d071

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page