A simple, fast, and feature-rich command-line weather tool with multiple data sources and output formats.
- π 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
# 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 .
# 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
San JosΓ©, CR: 22Β°C, Partly Cloudy
Feels like: 25Β°C | Humidity: 65% | Wind: 8 km/h
San JosΓ©, CR
\ / 22Β°C
.-. Partly Cloudy
β ( ) β β 8 km/h
`-' 65% humidity
/ \
{
"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
}
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
The tool uses a configuration file at ~/.weather.conf
(JSON format):
{
"units": "metric",
"format": "simple",
"source": "open-meteo",
"cache_duration": 300,
"timeout": 10
}
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 |
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
- Status: Implemented and working
- Coverage: Global
- Features: Current weather, forecasts, no API key required
- Rate limit: Generous free tier
- URL: https://open-meteo.com/
- Status: Placeholder implemented
- Coverage: Global
- Features: Simple curl-based service, ASCII art built-in
- Rate limit: Fair use
- Status: Placeholder implemented
- Coverage: United States only
- Features: Official US government weather data
- Rate limit: None (government API)
requests>=2.25.0
- HTTP requestsurllib3>=1.26.0
- HTTP client utilities
Development dependencies:
pytest
- Testing framework
# Run all tests
pytest
# Run with coverage
pytest --cov=weather
# Run specific test file
pytest tests/test_location.py -v
# 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
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"
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
- Open-Meteo for providing excellent free weather API
- OpenStreetMap Nominatim for geocoding services
- Weather icons inspired by wttr.in ASCII art