Skip to content

AriGameS/FlightsAPI

Repository files navigation

up# Israeli Flight Information API

A Flask-based REST API that provides real-time flight information for Israeli airports, primarily Ben Gurion International Airport. The API scrapes data from the Israel Airports Authority (IAA) website and includes fallback options for third-party aviation APIs.

Features

  • Real-time Flight Data: Get live arrivals and departures from Ben Gurion Airport
  • Multiple Data Sources: Primary scraper with Aviation Edge API fallback
  • Redis Caching: High-performance caching with in-memory fallback
  • Docker Support: Fully containerized with Docker Compose
  • RESTful API: Clean, well-documented endpoints
  • Error Handling: Comprehensive error handling and logging
  • Health Checks: Built-in health monitoring
  • Configuration Management: Environment-based configuration

API Endpoints

Core Endpoints

  • GET / - API information and available endpoints
  • GET /health - Health check with cache status
  • GET /flights/arrivals - Get arriving flights
  • GET /flights/departures - Get departing flights
  • GET /flights/{flight_number} - Get specific flight information

Management Endpoints

  • GET /cache/info - Cache statistics and information
  • POST /cache/clear - Clear all cached data
  • GET /config - API configuration information

Query Parameters

  • page - Page number for pagination (default: 1)
  • per_page - Items per page (default: 50, max: 100)
  • mock - Use mock data instead of live data (default: false)

Quick Start

Using Docker Compose (Recommended)

  1. Clone and navigate to the project:
git clone <repository-url>
cd API-Project
  1. Start the services:
docker-compose up -d
  1. Test the API:
curl http://localhost:5000/health

Manual Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Start Redis (optional, will fallback to in-memory cache):
redis-server
  1. Run the application:
python app.py

Configuration

Configure the API using environment variables:

Core Configuration

  • DEBUG - Enable debug mode (default: false)
  • PORT - Server port (default: 5000)
  • HOST - Server host (default: 0.0.0.0)
  • LOG_LEVEL - Logging level (default: INFO)

Redis Configuration

  • REDIS_HOST - Redis server host (default: localhost)
  • REDIS_PORT - Redis server port (default: 6379)
  • REDIS_DB - Redis database number (default: 0)

Cache Configuration

  • CACHE_DEFAULT_TTL - Default cache TTL in seconds (default: 300)
  • FLIGHT_CACHE_TTL - Flight-specific cache TTL (default: 180)

API Configuration

  • AVIATION_EDGE_API_KEY - Aviation Edge API key (optional)
  • USE_MOCK_DATA - Force use of mock data (default: false)
  • MAX_PER_PAGE - Maximum items per page (default: 100)
  • DEFAULT_PER_PAGE - Default items per page (default: 50)

Scraper Configuration

  • SCRAPER_TIMEOUT - HTTP request timeout (default: 10)

Example Usage

Get Flight Arrivals

curl "http://localhost:5000/flights/arrivals?page=1&per_page=10"

Get Specific Flight

curl "http://localhost:5000/flights/LY315"

Use Mock Data for Testing

curl "http://localhost:5000/flights/departures?mock=true"

Response Format

Flight Object

{
  "flight_number": "LY315",
  "airline": "EL AL",
  "flight_type": "departure",
  "scheduled_time": "2025-01-15T14:30:00",
  "actual_time": "2025-01-15T14:35:00",
  "estimated_time": null,
  "status": "departed",
  "origin": "Tel Aviv",
  "destination": "New York",
  "terminal": "Terminal 3",
  "gate": "Gate 15",
  "aircraft_type": "Boeing 777"
}

Paginated Response

{
  "flights": [...],
  "total_count": 45,
  "page": 1,
  "per_page": 10,
  "last_updated": "2025-01-15T12:00:00"
}

Data Sources

  1. Primary: Israel Airports Authority (IAA) website scraper
  2. Fallback: Aviation Edge API (requires API key)
  3. Development: Mock data generator

Architecture

├── app.py                 # Main Flask application
├── config.py              # Configuration management
├── models/
│   ├── __init__.py
│   └── flight.py         # Flight data models
├── services/
│   ├── __init__.py
│   ├── flight_scraper.py # IAA website scraper
│   ├── aviation_api.py   # Aviation Edge API client
│   └── cache.py          # Redis caching service
├── requirements.txt       # Python dependencies
├── Dockerfile            # Container definition
├── docker-compose.yml    # Multi-service setup
└── README.md             # This file

Development

Running Tests

# Test with mock data
curl "http://localhost:5000/flights/arrivals?mock=true"

# Check health status
curl "http://localhost:5000/health"

# View cache information
curl "http://localhost:5000/cache/info"

Building Docker Image

docker build -t israeli-flight-api .

Development Mode

export DEBUG=true
export LOG_LEVEL=DEBUG
python app.py

Monitoring

The API includes built-in health checks and monitoring:

  • Health endpoint provides service status and cache information
  • Comprehensive logging with configurable levels
  • Docker health checks for container orchestration
  • Redis connection monitoring with fallback handling

Limitations

  • Primary data source depends on IAA website structure
  • Rate limiting not implemented (relies on caching)
  • Currently focused on Ben Gurion Airport (TLV)
  • Aviation Edge API requires paid subscription for production use

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is open source and available under the MIT License.

About

A basic flight flask api that let you get information about incoming/ history flights

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published