From c78aea671c1eb8ddd4a9de408e8e0bf9859582c8 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 2 Jul 2020 21:53:12 -0400 Subject: [PATCH] move common schedule code to library --- schedule/ics.php | 32 +------------------------------- schedule/index.php | 32 +------------------------------- schedule/schedule.php | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 62 deletions(-) create mode 100644 schedule/schedule.php diff --git a/schedule/ics.php b/schedule/ics.php index cf47f6c..581daa9 100644 --- a/schedule/ics.php +++ b/schedule/ics.php @@ -1,35 +1,5 @@ [ - "method" => "GET", - "header" => "X-API-Key: $apikey\r\n" - ] -]); - -$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"]; -}); - -function formatdate($date) { - return gmdate("Ymd\THis\Z", strtotime($date)); -} +include 'schedule.php'; header("Content-Type: text/calendar"); diff --git a/schedule/index.php b/schedule/index.php index 6840910..acaf7ed 100644 --- a/schedule/index.php +++ b/schedule/index.php @@ -1,36 +1,6 @@ [ - "method" => "GET", - "header" => "X-API-Key: $apikey\r\n" - ] -]); - -$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"]; -}); - -function formatdate($date) { - return gmdate("D M d H:i", strtotime($date)); -} +include 'schedule.php'; ?>

tilderadio.org

diff --git a/schedule/schedule.php b/schedule/schedule.php new file mode 100644 index 0000000..6a14f7e --- /dev/null +++ b/schedule/schedule.php @@ -0,0 +1,34 @@ + [ + "method" => "GET", + "header" => "X-API-Key: $apikey\r\n" + ] +]); + +$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"]; +}); + +function formatdate($date) { + return gmdate("D M d H:i", strtotime($date)); +} +