#!/usr/bin/env python3
"""Observable data loader: fetches /contributions/ from the API."""
import json
import os
import urllib.request
import urllib.error

API_BASE = os.environ.get("API_BASE", "http://127.0.0.1:8000").rstrip("/")

try:
    with urllib.request.urlopen(f"{API_BASE}/contributions/", timeout=10) as resp:
        data = json.loads(resp.read())
    print(json.dumps(data))
except urllib.error.URLError as e:
    print(json.dumps({"error": str(e), "contributions": []}))
