This project fetches weather data from OpenWeatherMap API and uploads it to Google Drive. It includes both a standalone Python script and an Airflow DAG implementation.
- Fetches current weather data for Karachi from OpenWeatherMap API
- Transforms data by converting temperature from Kelvin to Celsius and adding metadata
- Saves data as JSON files with timestamps
- Uploads files to Google Drive using service account authentication
- Includes both a standalone Python script and an Airflow DAG implementation
weather_standalone.py
: Run this script directly to fetch weather data without Airflow
dags/weather_etl.py
: An Airflow DAG that can be deployed to an existing Airflow instance
- Python 3.8+
- OpenWeatherMap API key
- Google Drive API credentials (service account)
git clone <repository-url>
cd weatherApp_airflow
pip install -r requirements.txt
Create a .env
file in the project root:
OPENWEATHERMAP_API_KEY=your_api_key
Place your service account JSON file in the project root and update the path in the scripts if necessary.
python weather_standalone.py
Copy the DAG file to your Airflow dags folder:
cp dags/weather_etl.py ~/airflow/dags/
Then activate the DAG from the Airflow UI.
weatherApp_airflow/
├── .env # Environment variables
├── .gitignore # Git ignore file
├── README.md # This file
├── requirements.txt # Python dependencies
├── dags/ # Airflow DAGs
│ └── weather_etl.py # Weather ETL DAG
├── weather_standalone.py # Standalone weather script
└── service-account-key.json # Google Drive API service account key (you must add this)
You can modify the following variables in the dags/weather_etl.py
file:
city_name
: The city for which to fetch weather data (default: "Karachi")SERVICE_ACCOUNT_FILE
: Path to your service account key fileFOLDER_ID
: Your Google Drive folder ID where files will be uploaded
If you encounter issues with Google Drive authentication, make sure:
- Your service account key file is correctly placed and the path is properly set in the code
- The service account has permission to access the specified Google Drive folder
- The Google Drive API is enabled for your project
This project is licensed under the MIT License - see the LICENSE file for details.