Live Ansicht
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user