#!/usr/bin/env bash
# news_fetch.sh – Fetch Swiss news, bypassing proxy
# Unsets HTTP_PROXY/HTTPS_PROXY to avoid proxy interference
set -euo pipefail

# Bypass proxy for external APIs
unset HTTP_PROXY 2>/dev/null || true
unset HTTPS_PROXY 2>/dev/null || true
unset http_proxy 2>/dev/null || true
unset https_proxy 2>/dev/null || true

echo "=== FRIDAY News – Swiss Sources ==="
echo ""

# Fetch from swissinfo.ch (English)
echo "--- swissinfo.ch ---"
curl -s --max-time 10 \
  "https://www.swissinfo.ch/eng.rss" 2>/dev/null | \
  python3 -c "
import sys, xml.etree.ElementTree as ET
try:
    root = ET.fromstring(sys.stdin.read())
    for item in root.findall('.//item')[:5]:
        title = item.find('title').text
        link = item.find('link').text
        print(f'📰 {title}')
        print(f'   {link}')
        print()
except Exception as e:
    print(f'Parse error: {e}')
    print('Raw fallback:')
    sys.stdin.seek(0)
    print(sys.stdin.read()[:2000])
" 2>/dev/null || echo "  (swissinfo unavailable)"

echo ""
echo "--- NZZ (top headlines via web search) ---"
# Use web_search as fallback since NZZ RSS may be paywalled
# This will be handled by the agent's web_search tool in the briefing
