Live Ansicht

This commit is contained in:
Gogs
2026-07-07 12:37:28 +02:00
parent c2da564dd6
commit 5abbe9220e
5 changed files with 247 additions and 1 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
require_once '/var/www/src/Config.php';
require_once '/var/www/src/Services/ProgrammeService.php';
header('Content-Type: application/json; charset=utf-8');
$config = new Config(
'/var/www/config/config.json',
'/var/www/config/channels.json'
);
$timezone = $config->get('timezone', 'Europe/Vienna');
$cacheFile = '/var/www/cache/guide.json';
if (!file_exists($cacheFile)) {
http_response_code(404);
echo json_encode([
'error' => 'guide.json not found',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
$data = json_decode(file_get_contents($cacheFile), true);
if (!is_array($data)) {
http_response_code(500);
echo json_encode([
'error' => 'guide.json is invalid',
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
$service = new ProgrammeService($timezone);
$items = $service->getCurrentProgrammes($data, $config);
$now = new DateTimeImmutable('now', new DateTimeZone($timezone));
echo json_encode([
'now' => $now->format(DateTimeInterface::ATOM),
'timestamp' => $now->getTimestamp(),
'items' => $items,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);