"""
NASA — Astronomy Picture of the Day Demo
=========================================
A minimal, ready-to-run example of fetching NASA's APOD.

Get an API key (free, instant):
    1. Go to https://api.nasa.gov and fill in the short "Generate API Key" form.
    2. The key is emailed to you immediately (and shown on the page).
    3. For light testing you can skip this and use "DEMO_KEY".

Setup:
    pip install requests
    export NASA_API_KEY="..."     # or use "DEMO_KEY" for light testing

Run:
    python nasa_demo.py
"""

import os
import requests


def apod() -> dict:
    """Return today's Astronomy Picture of the Day metadata."""
    response = requests.get(
        "https://api.nasa.gov/planetary/apod",
        params={"api_key": os.environ.get("NASA_API_KEY", "DEMO_KEY")},
    )
    response.raise_for_status()
    return response.json()


if __name__ == "__main__":
    data = apod()
    print(f"{data['title']}\n{data.get('url', '')}")
