From 76c878d65a8efe1e5c4b23070e8b036f58603217 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Sat, 26 Sep 2020 19:02:06 +0000 Subject: [PATCH] allow for remote development of schedule by pointing to live schedule json in dev --- schedule/schedule.php | 52 ++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/schedule/schedule.php b/schedule/schedule.php index 5afb0ad..74f0883 100644 --- a/schedule/schedule.php +++ b/schedule/schedule.php @@ -2,31 +2,37 @@ include 'apikey.php'; 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" => [ + "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" => [ + "method" => "GET", + "header" => "X-API-Key: $apikey\r\n" + ] + ]); + + // allow ics.php to overwrite $from and $to + if (!isset($from,$to)) { + $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")); + } + + $schedule = json_decode( + file_get_contents( + "https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to", + false, + $context + ), + true + ); } -$context = stream_context_create([ - "http" => [ - "method" => "GET", - "header" => "X-API-Key: $apikey\r\n" - ] -]); - -// allow ics.php to overwrite $from and $to -if (!isset($from,$to)) { - $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")); -} - -$schedule = json_decode( - file_get_contents( - "https://radio.tildeverse.org/api/station/1/streamers/schedule?start=$from&end=$to", - false, - $context - ), - true -); - usort($schedule, function ($a, $b) { return $a["start"] <=> $b["start"]; });