A simple, elegant command-line interface for fetching real-time weather information from OpenWeatherMap API.
- π Get weather for any city worldwide
- π‘οΈ Detailed weather information including temperature, humidity, wind speed, and more
- π§ Configurable temperature units (Celsius, Fahrenheit, Kelvin)
- π Secure API key management via environment variables
- β¨ Clean, modular Python code with type hints
- π§ͺ Comprehensive error handling
- π¦ Easy installation and setup
- Python 3.7 or higher
- pip (Python package manager)
- An OpenWeatherMap API key (get one free here)
- Clone this repository:
git clone https://github.com/codeforgood-org/weather-cli.git
cd weather-cli- Install dependencies:
pip install -r requirements.txt- Set up your API key:
export OPENWEATHER_API_KEY='your_api_key_here'Or create a .env file:
echo "OPENWEATHER_API_KEY=your_api_key_here" > .envInstall as a package for system-wide access:
pip install -e .Get weather for a city:
python -m weather_cli.cli LondonOr if installed as a package:
weather-cli LondonFor cities with spaces in their names:
python -m weather_cli.cli New York
python -m weather_cli.cli San FranciscoChoose your preferred temperature unit:
# Celsius (default)
python -m weather_cli.cli Tokyo
# Fahrenheit
python -m weather_cli.cli Tokyo --units imperial
# Kelvin
python -m weather_cli.cli Tokyo --units standard# Get weather for Paris
$ python -m weather_cli.cli Paris
Weather in Paris, FR:
Description: Clear sky
Temperature: 18.5Β°C (feels like 17.8Β°C)
Humidity: 65%
Pressure: 1015 hPa
Wind Speed: 3.5 m/s
Cloudiness: 10%weather-cli/
βββ weather_cli/ # Main package directory
β βββ __init__.py # Package initialization
β βββ cli.py # Command-line interface
β βββ config.py # Configuration management
β βββ weather.py # Weather data fetching and processing
βββ tests/ # Test directory
β βββ __init__.py
β βββ test_config.py
β βββ test_weather.py
β βββ test_cli.py
βββ .env.example # Example environment variables
βββ .gitignore # Git ignore rules
βββ LICENSE # MIT License
βββ README.md # This file
βββ requirements.txt # Production dependencies
βββ requirements-dev.txt # Development dependencies
βββ pyproject.toml # Project configuration
Install development dependencies:
pip install -r requirements-dev.txtRun tests:
pytestRun tests with coverage:
pytest --cov=weather_cli --cov-report=htmlThis project uses various tools to maintain code quality:
# Format code with black
black weather_cli tests
# Sort imports
isort weather_cli tests
# Lint with flake8
flake8 weather_cli tests
# Type checking with mypy
mypy weather_cliOPENWEATHER_API_KEY(required): Your OpenWeatherMap API keyWEATHER_UNITS(optional): Default temperature units (metric,imperial, orstandard)
- Visit OpenWeatherMap
- Sign up for a free account
- Navigate to API Keys section
- Generate a new API key
- Add it to your environment variables
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and follow the code style guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Weather data provided by OpenWeatherMap
- Built with β€οΈ by codeforgood-org
If you encounter any issues or have questions:
- Check the Issues page
- Create a new issue if your problem isn't already listed
- Provide as much detail as possible including error messages and your environment
Future enhancements planned:
- 5-day weather forecast
- Multiple city comparison
- Weather alerts and notifications
- Historical weather data
- Colorized terminal output
- JSON output format option
- Configuration file support
Made with Python π