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 requestsurllib3>=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
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Run tests (
pytest) - Commit your changes (
git commit -am 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Open-Meteo for providing excellent free weather API
- OpenStreetMap Nominatim for geocoding services
- Weather icons inspired by wttr.in ASCII art
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d35cacd01bc8220078946f5803863940d612188fccecff35fd73074022c249fc
|
|
| MD5 |
29fff645ce902747a051283fab13a8d4
|
|
| BLAKE2b-256 |
cfded728009aa453111cc8345c4d24d0ff9f4d01cfdde5f4dcb302227e0bf551
|
File details
Details for the file cr_mb_weather_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cr_mb_weather_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 31.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26c1b72216bf14d9c8648c31273c304917955846781180cd5d8c6455a7ddc6ef
|
|
| MD5 |
b7fc9adb9256fb13141e720d10db2c98
|
|
| BLAKE2b-256 |
731ff8761e783ec4876617ac17029d98dce78c53975bbc9391190b78ac04d071
|