allow for remote development of schedule by pointing to live schedule json in dev

This commit is contained in:
James Tomasino 2020-09-26 19:02:06 +00:00
parent af00cded1e
commit 76c878d65a
1 changed files with 29 additions and 23 deletions

View File

@ -2,30 +2,36 @@
include 'apikey.php'; include 'apikey.php';
if (empty($apikey)) { if (empty($apikey)) {
die("missing api key"); /* If we don't have the API key, assume we're developing. Pull data from live version of this file */
} $context = stream_context_create([
"http" => [
$context = stream_context_create([ "method" => "GET",
]
]);
$schedule = json_decode(file_get_contents("https://tilderadio.org/schedule/schedule.php?json=yes", false, $context), true);
} else {
$context = stream_context_create([
"http" => [ "http" => [
"method" => "GET", "method" => "GET",
"header" => "X-API-Key: $apikey\r\n" "header" => "X-API-Key: $apikey\r\n"
] ]
]); ]);
// allow ics.php to overwrite $from and $to // allow ics.php to overwrite $from and $to
if (!isset($from,$to)) { if (!isset($from,$to)) {
$from = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 1 day")); $from = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 1 day"));
$to = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 8 days")); $to = gmdate("Y-m-d\TH:i:s\Z", strtotime("now + 8 days"));
} }
$schedule = json_decode( $schedule = json_decode(
file_get_contents( file_get_contents(
"https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to", "https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to",
false, false,
$context $context
), ),
true true
); );
}
usort($schedule, function ($a, $b) { usort($schedule, function ($a, $b) {
return $a["start"] <=> $b["start"]; return $a["start"] <=> $b["start"];