A comprehensive Python weather data fetcher CLI tool with REST API and web dashboard. Retrieve current weather, historical weather data, and weather forecasts from OpenWeatherMap API. Features multi-mode CLI, RESTful API endpoints, data visualization, encrypted API key management, and responsive web UI for seamless weather data integration.
-
Multiple Weather Modes:
- Current Weather Data
- Historical Weather Data
- Forecasted Weather Data
-
Flexible Operation Modes:
- CLI Interface with interactive and batch modes
- REST API with FastAPI
- Modern Web UI
-
Runtime Mode Switching: Switch between different modes using parameters at runtime
-
Secure API Key Management: Encrypted storage of API keys with no exposed secrets
-
Data Visualization: Built-in matplotlib/seaborn visualization for weather data
-
Configurable: YAML configuration and environment variable support
-
Modular Architecture: Clean separation of concerns with reusable components
- Python 3.8 or higher
- OpenWeatherMap API key (get one free at https://openweathermap.org/api)
- Clone the repository:
git clone <repository-url>
cd new_implementation- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Configure API key:
cp .env.example .env
# Edit .env and add your OpenWeatherMap API keyCreate a .env file in the project root with the following variables:
OPENWEATHER_API_KEY=your_api_key_here
LATITUDE=20.2910
LONGITUDE=85.8456
DEFAULT_UNITS=metric
DEFAULT_LANGUAGE=en
LOG_LEVEL=INFOYou can also use config/config.yaml for more complex configurations:
api:
base_url: "https://api.openweathermap.org/data/2.5"
current_weather_url: "/weather"
forecast_url: "/onecall"
historical_url: "/onecall/timemachine"
location:
latitude: 20.2910
longitude: 85.8456
timezone: "Asia/Kolkata"
units:
standard:
temperature: "K"
speed: "m/s"
metric:
temperature: "°C"
speed: "m/s"
imperial:
temperature: "°F"
speed: "mph"
languages:
english: "en"
hindi: "hi"
exclusion_options:
- "current"
- "minutely"
- "hourly"
- "daily"
- "alerts"python -m src.main --mode interactivepython -m src.main --mode current --location "New York" --units metricpython -m src.main --mode historical --days-back 1 --units metric --visualizepython -m src.main --mode forecast --days 5 --exclude minutely,hourly --units metric --visualizeStart the API server:
python -m src.api.mainThe API will be available at http://localhost:8000
-
GET /api/weather/current- Get current weather- Query params:
q(location),units,lang
- Query params:
-
GET /api/weather/historical- Get historical weather- Query params:
lat,lon,dt(timestamp),units,lang
- Query params:
-
GET /api/weather/forecast- Get weather forecast- Query params:
lat,lon,exclude,units,lang
- Query params:
-
GET /docs- Interactive API documentation (Swagger UI)
Start the web application:
python -m src.api.main --uiAccess the web UI at http://localhost:8000
You can switch modes at runtime using parameters:
From CLI:
# Start in interactive mode, then execute specific commands
python -m src.main --mode interactive
# Inside interactive mode, you can switch modes by typing:
> mode current
> mode historical
> mode forecastFrom API:
# Switch mode by calling different endpoints
curl http://localhost:8000/api/weather/current?q=London
curl http://localhost:8000/api/weather/forecast?lat=20.29&lon=85.84From Config: Override default mode using environment variables:
WEATHER_MODE=historical python -m src.main --mode batchWeather data is printed to the console in a formatted JSON structure.
Weather data is automatically saved to outputs/ directory with timestamped filenames:
CurrentWeatherData_<timestamp>.jsonHistoricalWeatherData_<timestamp>.jsonForecastedWeatherData_<timestamp>.json
When --visualize flag is used, matplotlib/seaborn charts are generated showing temperature trends.
weather_fetcher_api/
├── src/
│ ├── weather_fetchers/ # Weather data fetching classes
│ │ ├── base.py # Abstract base class
│ │ ├── current.py # Current weather fetcher
│ │ ├── historical.py # Historical weather fetcher
│ │ └── forecast.py # Forecast weather fetcher
│ ├── utils/ # Utility modules
│ │ ├── config.py # Configuration loader
│ │ ├── security.py # API key encryption/decryption
│ │ ├── datetime_utils.py # Date/time utilities
│ │ ├── storage.py # Data storage utilities
│ │ ├── visualization.py # Visualization utilities
│ │ ├── logger.py # Logging configuration
│ │ └── exceptions.py # Custom exceptions
│ ├── api/ # REST API
│ │ ├── main.py # FastAPI application
│ │ └── routes.py # API endpoints
│ └── main.py # CLI entry point
├── frontend/ # Web UI
│ ├── templates/ # HTML templates
│ └── static/ # CSS and JS
│ ├── css/
│ └── js/
├── tests/ # Unit and integration tests
├── examples/ # Usage examples
├── config/ # Configuration files
├── outputs/ # Output data (not tracked in git)
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
├── requirements.txt # Python dependencies
├── README.md # This file
├── agents.md # Development guidelines
└── CHANGELOG.md # Version history
pytest tests/With coverage:
pytest --cov=src tests/black src/ tests/flake8 src/ tests/mypy src/- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m '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.
- OpenWeatherMap API for providing weather data
- FastAPI for the excellent web framework
- Matplotlib and Seaborn for visualization capabilities
For issues, questions, or contributions, please open an issue on the GitHub repository.