"""
Airtable — List Records Demo
=============================
A minimal, ready-to-run example of listing records from an Airtable table.

Get an API key (free):
    1. Create an account at https://airtable.com
    2. Go to https://airtable.com/create/tokens, create a personal access
       token with the data.records:read scope and access to your base.
    3. Find your base ID (starts with "app") at https://airtable.com/api
       by selecting the base.

Setup:
    pip install requests
    export AIRTABLE_API_KEY="pat..."
    export AIRTABLE_BASE_ID="app..."
    export AIRTABLE_TABLE="Table 1"

Run:
    python airtable_demo.py
"""

import os
import requests


def list_records() -> list:
    """Return records from an Airtable table."""
    base = os.environ.get("AIRTABLE_BASE_ID")
    table = os.environ.get("AIRTABLE_TABLE")
    response = requests.get(
        f"https://api.airtable.com/v0/{base}/{table}",
        headers={"Authorization": f"Bearer {os.environ.get('AIRTABLE_API_KEY')}"},
    )
    response.raise_for_status()
    return response.json()["records"]


if __name__ == "__main__":
    records = list_records()
    print(f"Fetched {len(records)} records")
