<?php
// fetch_satellite.php — динамический парсинг
date_default_timezone_set('UTC');
header('Content-Type: application/json; charset=utf-8');

$cache_file = __DIR__ . '/satellite_cache.json';
$data = json_decode(file_get_contents($cache_file), true) ?: [];

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');

// Пример: Space-Track RSS (можно заменить на API)
curl_setopt($ch, CURLOPT_URL, 'https://www.space-track.org/rss/news');
$xml = curl_exec($ch);
if ($xml) {
    $rss = simplexml_load_string($xml);
    if ($rss && isset($rss->channel->item[0])) {
        $data['analysis']['recent_events'][0] = date('d.m.Y') . ': ' . (string)$rss->channel->item[0]->title;
    }
}
curl_close($ch);

file_put_contents($cache_file, json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
echo json_encode(['status' => 'обновлено', 'aal' => $data['aal']]);
?>