<?php
// fetch_media.php — обновляет media_cache.json
date_default_timezone_set('UTC');

$cache_file = __DIR__ . '/media_cache.json';

// Здесь — ваш реальный API (NewsAPI, X API, Google News, etc.)
// Пример с имитацией:
$real_data = [
    'last_update' => date('d.m.Y H:i') . ' UTC',
    'mentions_24h' => rand(1400, 1600),
    'chart_data' => array_map(fn($v)=>$v+rand(-60,60), [620,580,710,890,1120,980,1340,1560,1420,1080,1520]),
    'aal' => 0, // будет пересчитано
    'top_mentions' => [
        ['source'=>'Haaretz','title'=>'Israel returns 30 Palestinian bodies','time'=>date('H:i')],
        ['source'=>'Al Jazeera','title'=>'Gaza truce tested by new strikes','time'=>date('H:i')],
        ['source'=>'X (@user)','title'=>'Breaking: IDF statement','time'=>date('H:i')]
    ]
];

file_put_contents($cache_file, json_encode($real_data, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));
echo json_encode(['status'=>'updated', 'time'=>date('H:i')]);
?>