Skip to content

oVitorio-ac/climate-data-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌀️ Climate Data Service

Service for collecting climate data, implementing an ETL pipeline to monitor weather conditions in different Brazilian cities.

πŸ—οΈ Architecture

The project uses Docker containers to orchestrate:

  • ETL Service: Python pipeline for weather data collection
  • REST API: Spring Boot application to expose the data
  • PostgreSQL: Database for storage

πŸš€ How to Run

Prerequisites

  • Docker and Docker Compose installed
  • WeatherAPI.com API key (free)

1. Initial Setup

# Clone the repository
git clone <your-repository>
cd climate-data-service

# Copy the environment variables example file
cp env.example .env

# Edit the .env file and add your API key
nano .env

2. Configure Environment Variables

Edit the .env file and add your API key:

API_KEY=your_api_key_here

Get your free key at: https://www.weatherapi.com/

3. Run with Docker Compose

# Build and start all services
docker-compose up -d

# View ETL service logs
docker-compose logs -f climate-etl

# View PostgreSQL logs
docker-compose logs -f postgres

4. Access the Services

πŸ“Š Monitoring

Check Container Status

docker-compose ps

View Real-Time Logs

# All services
docker-compose logs -f

# Only ETL
docker-compose logs -f climate-etl

Check Data in Database

# Connect to PostgreSQL
docker-compose exec postgres psql -U climate_user -d climate_db

# Query data
SELECT * FROM weather ORDER BY created_at DESC LIMIT 10;

# Run useful queries
\i data/queries.sql

Test the REST API

# List all records
curl http://localhost:8081/clima

# Search by city
curl http://localhost:8081/clima/Campinas

# Get today's data for a city
curl http://localhost:8081/clima/Campinas/hoje

# API health check
curl http://localhost:8081/health

πŸ› οΈ Useful Commands

# Stop all services
docker-compose down

# Stop and remove volumes (warning: deletes data)
docker-compose down -v

# Rebuild containers
docker-compose up --build -d

# Run only the ETL (without scheduling)
docker-compose run --rm climate-etl python etl_project/etl_pipeline.py

# Backup the database
docker-compose exec postgres pg_dump -U climate_user -d climate_db > data/backup_$(date +%Y%m%d_%H%M%S).sql

πŸ“ Project Structure

climate-data-service/
β”œβ”€β”€ etl_project/          # ETL pipeline code
β”‚   β”œβ”€β”€ config/          # Configurations
β”‚   β”œβ”€β”€ utils/           # Utilities
β”‚   β”œβ”€β”€ main.py          # Entry point
β”‚   β”œβ”€β”€ etl_pipeline.py  # Main pipeline
β”‚   β”œβ”€β”€ Dockerfile       # ETL app container
β”‚   └── requirements.txt # Python dependencies
β”œβ”€β”€ api/                  # Spring Boot application
β”‚   β”œβ”€β”€ src/main/java/   # Java code
β”‚   β”œβ”€β”€ src/main/resources/ # Configurations
β”‚   β”œβ”€β”€ src/test/        # Tests
β”‚   β”œβ”€β”€ Dockerfile       # API container
β”‚   └── pom.xml          # Maven dependencies
β”œβ”€β”€ data/                # Database files
β”‚   β”œβ”€β”€ init.sql         # Initialization script
β”‚   β”œβ”€β”€ backup.sql       # Backup script
β”‚   β”œβ”€β”€ queries.sql      # Useful queries
β”‚   └── README.md        # Data documentation
β”œβ”€β”€ logs/                # Application logs
β”œβ”€β”€ docker-compose.yml   # Container orchestration
β”œβ”€β”€ env.example         # Environment variable example
└── .gitignore          # Git ignored files

πŸ”§ Configuration

Monitored Cities

Edit etl_project/config/config.yaml to change the cities:

cities:
  - Campinas
  - Limeira
  - Americana
  - Sao Paulo
  - Rio de Janeiro

Collection Frequency

In etl_project/config/config.yaml, change the interval:

schedule:
  interval:
    value: 30
    unit: seconds

πŸ“ˆ Collected Data

The system automatically collects:

  • Temperature (Celsius)
  • Wind speed (km/h)
  • Relative humidity (%)
  • Location (city, region, country)
  • Collection timestamp

πŸ› Troubleshooting

Problem: ETL container does not start

# Check logs
docker-compose logs climate-etl

# Check if PostgreSQL is healthy
docker-compose ps postgres

Problem: Database connection error

# Check if environment variables are correct
docker-compose exec climate-etl env | grep POSTGRESQL

Problem: API does not respond

πŸ“ Logs

Logs are saved in:

  • ./logs/ (mounted volume in the container)
  • Container console (via docker-compose logs)

πŸ”’ Security

  • Database credentials are set in docker-compose.yml
  • The API key must be kept safe in the .env file
  • The .env file should not be committed to the repository

πŸ“ž Support

For issues or questions:

  1. Check the logs: docker-compose logs
  2. See WeatherAPI.com documentation
  3. Open an issue in the repository

🎯 Challenge Compliance

βœ… Requirements Met:

  1. ETL with Python βœ…

    • Python 3 script consuming weather API
    • Configurable city query
    • Data treatment and validation
    • Periodic scheduling
  2. PostgreSQL βœ…

    • Relational database structure
    • Creation scripts (init.sql)
    • Integrity and normalization
  3. REST API with Spring Boot βœ…

    • GET /clima - List all records
    • GET /clima/{cidade} - Filter by city
    • GET /clima/{cidade}/hoje - Most recent data of the day
  4. Containerization βœ…

    • Python container (ETL)
    • PostgreSQL container
    • Spring Boot container (API)
    • docker-compose.yml for orchestration

πŸš€ Implemented Differentials:

  • Swagger Documentation: Interactive API interface
  • Health Checks: Service health monitoring
  • Structured logs: Easier debugging
  • Automated tests: Test structure configured
  • Multi-stage Docker builds: Image optimization

🀝 Contributing

See the contribution guidelines.

πŸ“ License

This project is licensed under the MIT License.

About

ETL and REST API solution for collecting, storing, and exposing real-time weather data from multiple Brazilian cities. Built with Python, Spring Boot, and PostgreSQL, fully containerized with Docker. Includes Swagger docs, health checks, and bilingual documentation.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors